how to add a file end of character to a file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mamul
    New Member
    • Oct 2008
    • 23

    #1

    how to add a file end of character to a file

    char * buff
    fread(buff,size of(char *), 1, fr);
    while(!feof(fr) )
    {
    fwrite(buff, sizeof(char *), 1, fw);
    fread(buff,size of(char *), 1, fr);
    }
    fread(memblock, sizeof(char), 1, fr);
    fwrite(memblock , sizeof(char), 1, fw);

    hi this is working in windows
    when i am trying to copy in linux..only the end fo file character is unable to copy to the fw. please anyone tell me how to write the eof(fr) to fw.

    thanks
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You should not have to actually write and end of file. The end of file marker should be written by fwrite after the data.

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      Originally posted by weaknessforcats
      You should not have to actually write and end of file. The end of file marker should be written by fwrite after the data.
      That doesn't quite make sense, how would fwrite know that it was the last call you were going to make to it before calling fclose. But the EOF marker might be put in place as you close the file with fclose.

      TBH I thought that EOF markers were a thing of the past (weren't they required by tape drives or something like that) that are not required and rarely used with modern storage media.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Where's JosAH when you need him?

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by weaknessforcats
          Where's JosAH when you need him?
          The saviour is here, fear no more! ;-) End of file characters are coupled to the
          stupidity of file systems. Early file systems just knew that a file was store at
          secors, say, 5, 9, 24, 42 (in that order) but didn't know for how much that last
          sector was filled by the file's data.

          The entire last sector was loaded in memory and the user (application) just had
          to guess. That's why they came up with a sentinel value, e.g. ^Z to denote the
          logical end of file. But what to do if the ^Z value happened to be part of the file
          in the last sector? Too bad, the file's length was just a multiple of a sector size.

          File systems nowadays do store the exact length of a file so there is no need
          anymore to read (or write) those silly sentinel values in the last sector. Deep
          down entire sectors are still read but that is way below the application level.

          Nowadays people forget to flush buffers (close() does it for them) and expect
          reading functions to be psychic, i.e. those functions are expected to predict
          whether or not they'll hit an end of file condition at their next read operation.

          Because no explicit end-of-file character is being written and because those
          single character reading functions have to indicate that they have just bumped
          into an end-of-file condition, they have to signal that condition with a sentinel
          value again. fgetc() does it by returning -1 which is outside the range of the
          valid character values but -1 is not written to a disk file image per se.

          kind regards,

          Jos

          Comment

          Working...