putting end of file character in binary file (cutting the file short) 
Author Message
 putting end of file character in binary file (cutting the file short)

hi, i have a problem with files. i have a file with binary data (binary
records). everything works fine except that if the user deletes one of
the records, i need to shorten the file. i have already come up with the
algorithm to move all records after the deleted record up, but this
leaves me with the last record at the end of the file. after deleting a
few records, these "surplus" records accumulate. basically what I need
is to be able to put an end of file marker in the middle of the file. i
know with text files you can do this by adding a Ctrl+Z character in the
middle of the file. but how about binary files? any help would be
appreciated. Thanks.

Shezan



Fri, 12 Jul 2002 03:00:00 GMT  
 putting end of file character in binary file (cutting the file short)
Binary files don't pay attention to end-of-file markers.

That's actually a lousy way to do it for text files as well,
unless you need to be cross-platform portable.

If you're using the API, use SetEndOfFile().

If you need a portable solution, your only choice is
to create a new file. See the C FAQ, 19.13 How
can a file be shortened in-place without completely
clearing or rewriting it?

http://www.eskimo.com/~scs/C-faq/q19.13.html

http://www.eskimo.com/~scs/C-faq/top.html

Quote:

>hi, i have a problem with files. i have a file with binary data (binary
>records). everything works fine except that if the user deletes one of
>the records, i need to shorten the file. i have already come up with the
>algorithm to move all records after the deleted record up, but this
>leaves me with the last record at the end of the file. after deleting a
>few records, these "surplus" records accumulate. basically what I need
>is to be able to put an end of file marker in the middle of the file.



Sat, 13 Jul 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Binary file I/O using ofstream::write() blows away remaining data to end of file

2. Keyboard short-cut wanted to switch between Cpp- and H-File

3. How to remove garbage characters at the end when doing file.read()

4. Spurious characters at end of file

5. CFile problem --- reading junk characters at the end of an file

6. How to remove garbage characters at the end when doing file.read()

7. file pointer at end of file?

8. URGENT !.Reading null character from binary files

9. Open a text file and search the file for a STRING of characters

10. Copying files with getc to putc doesn seem to like binary files:

11. Binary file read to New text file save grief

12. how to copy file(binary file) ?

 

 
Powered by phpBB® Forum Software