i am using a text file to store my data records. the data is stored in the following format.
Antony|9876543210 Azar|9753186420 Branda|1234567890 David|1357924680 John|6767676767
Thousands of records are stored in that file. i want to delete a particular record, say “David|1357924680”. I am using C, how to delete the particular record efficiently? currently i am using a temporary file to copy the records to that temp file by omitting the record i want to delete. and after copying to temp file, i copy the contents of the temp file to original file by truncating all the contents of the original file. i don’t think that i am doing it efficiently. Help me.
Add a column to your data indicating it is either a valid ( 1 ) or deleted ( 0 ) row:
When you want to delete a record, overwrite the single byte:
Branda is now deleted.
Then add a data file compression function which can be used to rewrite the file excluding deleted rows. This could be done during times of low or no usage so it doesn’t interfere with regular operations.
Edit
The validity column should probably be the first column so you can skip deleted rows more easily.