By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,952 Members | 1,424 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,952 IT Pros & Developers. It's quick & easy.

how to add a file end of character to a file

P: 23
char * buff
fread(buff,sizeof(char *), 1, fr);
while(!feof(fr))
{
fwrite(buff, sizeof(char *), 1, fw);
fread(buff,sizeof(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
Nov 16 '08 #1
Share this Question
Share on Google+
4 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
You should not have to actually write and end of file. The end of file marker should be written by fwrite after the data.
Nov 16 '08 #2

Banfa
Expert Mod 5K+
P: 8,916
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.
Nov 16 '08 #3

weaknessforcats
Expert Mod 5K+
P: 9,197
Where's JosAH when you need him?
Nov 17 '08 #4

Expert 10K+
P: 11,448
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
Nov 17 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.