inserting EOF in file

This is a discussion on inserting EOF in file within the C Programming forums, part of the General Programming Boards category; Hello. I am trying to delete some data from a file i opened. i thought that if i inserted the ...

  1. #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.

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    395
    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.

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,160
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 04:02 AM
  4. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  5. Hmm....help me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 09:57 AM

Tags for this Thread


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