C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 05-08-2008, 12:20 PM   #1
Registered User
 
Join Date: May 2008
Posts: 1
inserting EOF in file

Hello.
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   Reply With Quote
Old 05-08-2008, 12:49 PM   #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   Reply With Quote
Old 05-08-2008, 12:54 PM   #3
Senior software engineer
 
brewbuck's Avatar
 
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   Reply With Quote
Reply

Tags
delete, eof, file

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 08:25 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22