Deleting a record from a file

Thread Solved

Join Date: Dec 2004
Posts: 4
Reputation: PriyaJaiGanesh is an unknown quantity at this point 
Solved Threads: 0
PriyaJaiGanesh PriyaJaiGanesh is offline Offline
Newbie Poster

Deleting a record from a file

 
0
  #1
Dec 15th, 2004
hai!

(1)I have problem in deleting a record from a file.

I was told that the only way to delete a record from a file is to copy the file to another temporary file and then copy the records to the same file again by skipping the record that u need to delete i don't have problem until the copying of the file to the temporary file but i don't know how to skip the record that needs to be delete.

(2)what's the command to rename a file?

Plz anybody help me!


Urs,
PriyaJaiGanesh.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Deleting a record from a file

 
0
  #2
Dec 15th, 2004
read the old file, record for record.
Write all records to the tempfile, except the one(s) you want to delete.
Remove the old file.
Copy the tempfile completely to a new file with the same name as the old one.
Remove the tempfile.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 220
Reputation: frrossk is an unknown quantity at this point 
Solved Threads: 9
frrossk's Avatar
frrossk frrossk is offline Offline
Posting Whiz in Training

Re: Deleting a record from a file

 
0
  #3
Dec 15th, 2004
Originally Posted by PriyaJaiGanesh
(2)what's the command to rename a file?
int rename (const char *oldname, const char *newname)
The rename function renames the file oldname to newname. The file formerly accessible under the name oldname is afterwards accessible as newname instead. If rename fails, it returns -1.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 445
Reputation: 1o0oBhP is an unknown quantity at this point 
Solved Threads: 6
1o0oBhP's Avatar
1o0oBhP 1o0oBhP is offline Offline
Posting Pro in Training

Re: Deleting a record from a file

 
0
  #4
Dec 16th, 2004
(1)I have problem in deleting a record from a file.
Lets say you want to delete record 3 in a 10 record file:

  1. int rec_to_delete = 2; // record 3 is index 2
  2.  
  3. for(int i = 0; i < 9; i++)
  4. {
  5. if(i != rec_to_delete)
  6. {
  7. // copy record
  8. }
  9. }

use the if statement so that the record number you want to delete doesnt get copied.
http://sales.carina-e.com

no www
no nonsense

coming soon to a pc near you! :cool:
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC