GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 09-Jan-2006, 12:04
trinath trinath is offline
New Member
 
Join Date: Jan 2006
Posts: 3
trinath is on a distinguished road

File handling in C


Hi all,

I have a problem in handling files through C.

here is the problem im having:

i will query the database (for instance consider employees table )
for empno,ename,job,salary fields.The query returns me some 100 of rows. now i need to place them in a file in row wise pattern as they exist in the database.

now , if any row is updated in the database i need to update the same row in the file . also if any row is deleted i need to remove the same row in the file , and if any new row is inserted into the data base i need to insert the row in the file.

can any one suggest me any method to do this .
The performance is and main criteria(i mean time to do file operations. )

please help me in this regard,

thanks in advance,


Trinath Somanchi,
Hyderabad.
  #2  
Old 09-Jan-2006, 13:19
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,792
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: File handling in C


Quote:
Originally Posted by trinath
if any row is updated in the database i need to update the same row in the file . also if any row is deleted i need to remove the same row in the file , and if any new row is inserted into the data base i need to insert the row in the file.

A common method for editing files in general goes something like this:

Code:
1. Open the original (old) file for reading. 2. Open a new file for writing. Give it a temporary name: whatever you want. 3. Repeat this loop until the end of the old file is reached: If this is a place to insert a new line, then Write the new line to the new file and continue the loop. Read a line from the old file into memory. If this line is supposed to be edited then Make changes to the line in memory. If this line is not supposed to be deleted then Write the line from memory to the new file. 4. Close the old file and close the new file. 5. Delete the old file (or rename it to something else so that becomes the backup file for the original). 6. Rename the new file so that its name is the same as the original (old) file.


Quote:
Originally Posted by trinath
The performance is and main criteria(i mean time to do file operations. )

I don't know what this means. Reading and writing files is not something over which you have much control (disk buffering, etc. are functions of hardware and operating system software). Making the data base on disk have some kind of indexed structure where all records have exactly the same length might give some possibilities for optimizing access time, but I can't really know what might be appropriate without a lot more information.

Regards,

Dave
  #3  
Old 09-Jan-2006, 13:25
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,258
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: File handling in C


After you make all your changes in the database, rewrite the files. To try to change the file at the same time as the database defeats the purpose of the database itself. In other words, the reason for the database is so you don't have to manipulate flat files.

It's the same concept as purchasing a family car for the efficiency of transporting the family. Then when you have to go somewhere, half the family takes the car (your database), the other half takes their bicycles (your files). You're downgrading your efficiency and power for the sake of the old technology.
__________________

Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
 
 

Recent GIDBlogUS Elections and the ?Voter?s Responsibility? by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 08:44
CD Burner Help - Power Calibration Error.... JonBoy420 Computer Hardware Forum 110 05-Feb-2008 19:34
CD burner wont burn!! robertli55 Computer Hardware Forum 1 18-Jun-2004 11:53
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 12:28

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 09:56.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.