Thread: how to remove EOF byte at end of file?

  1. #1
    Registered User
    Join Date
    Jul 2018
    Posts
    3

    how to remove EOF byte at end of file?

    Hello all,

    I have written some data to a file using fprintf ... that was successful, however, when I opened the file in hex fiend, there was a 0xFF byte appended to the file, which I think is the EOF byte. I need for this file to actually end in 0x2F 0x00 for the program that uses the file. Can I either prevent the EOF byte from being written to the file, or delete the EOF byte?

    EDIT: Sorry, the byte at the end is now changing as I add more data, I'm not sure what it means... I tried to delete this post until I can figure out what exactly is happening and ask the proper question but I can't find the delete post button. My apologies.
    Last edited by maark6000; 07-26-2018 at 01:13 AM.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,532
    On current modern operating systems there is no "EOF" byte in the file.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,983
    > there was a 0xFF byte appended to the file, which I think is the EOF byte.
    You're right, 0xFF would typically be the result of casting the EOF constant to a char.

    Poor use of feof() can lead to that happening.
    Code:
    // BAD use of feof()
    while ( !feof(in) ) {
      ch = fgetc(in);  // BAD error checking for EOF here as well.
      fputc(ch,out)
    }
    > I have written some data to a file using fprintf...
    > I need for this file to actually end in 0x2F 0x00 for the program that uses the file
    It's quite hard to persuade fprintf to output '\0' characters, how are you managing that?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Jul 2018
    Posts
    3
    AH! I figured it out... I had a bad FOR loop and it was writing one extra fprintf statement, over-running the array and printing whatever garbage came after the array. Yes, thank you, apparently fprintf() will write cleanly to the file without EOF. My bad... thanks so much to all.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 01-22-2016, 03:20 AM
  2. File Comparision byte by byte
    By anusha2489 in forum C Programming
    Replies: 12
    Last Post: 05-16-2011, 06:58 AM
  3. end of file byte
    By Aisthesis in forum C++ Programming
    Replies: 2
    Last Post: 06-11-2009, 03:28 PM

Tags for this Thread