How i'm going to delete a record form a binary file?
Please give some idea on it.THANK!!
How i'm going to delete a record form a binary file?
Please give some idea on it.THANK!!
There are various ways..... one is to read all the data in, writing out only the records you want to a temporary file. When you're done reading, delete (or rename) the original file, and rename the temporary file to the main filename. If you don't want a temp file, read everything into memory instead.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
There's really no way to change just one record in a file, you have to read the entire file and write it back without the record you want, the same goes with insertion. The problem is that any method of modifying a record in place is inherently unsafe and error prone.
-Prelude
My best code is written with the delete key.
If your binary data has room for a flag which means 'deleted record', then you can just rewrite the record with this flag set.
This prevents the need for rewriting the whole file each time, but you do need to occasionally compact the file by removing all the deleted records.
Pretty much the same way you do a text file. Its not really different at all.