![]() |
| | #1 |
| Registered User Join Date: May 2008
Posts: 1
| inserting EOF in file I am trying to delete some data from a file i opened. i thought that if i inserted the ascii code of eof before the data i wanted to erase the new end of file would be there. Unfortunately, this didn't work. Why did this technique failed to work, and any other way i could delete some data from a file? Thanks in advance. |
| verbal is offline | |
| | #2 |
| Registered User Join Date: Apr 2008
Posts: 278
| There's no such thing as an EOF ascii code. EOF is just a numerical value (independent of the ascii encoding and system-dependent) returned by your read() function to indicate that there's nothing more to read in the file. To delete some data from a file, I don't think there another way (or at least a portable way) than deleting it completely (e.g. truncate option for open()) and rewritting it. But someone may have a better idea. |
| root4 is offline | |
| | #3 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| The portable way is to create a second file, then copy data from the first into the second until you've copied the number of bytes you want. Then remove the original and rename the new one back to the original name. The unportable way is to call truncate() on POSIX-like systems or SetEndOfFile() on Windows to drop the data directly from the end of the file. |
| brewbuck is offline | |
![]() |
| Tags |
| delete, eof, file |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| A development process | Noir | C Programming | 30 | 10-28-2009 04:24 AM |
| Formatting the contents of a text file | dagorsul | C++ Programming | 2 | 04-29-2008 12:36 PM |
| Can we have vector of vector? | ketu1 | C++ Programming | 24 | 01-03-2008 05:02 AM |
| airport Log program using 3D linked List : problem reading from file | gemini_shooter | C Programming | 3 | 03-04-2005 02:46 PM |
| Hmm....help me take a look at this: File Encryptor | heljy | C Programming | 3 | 03-23-2002 10:57 AM |