"ericunfuk" <xuwenduan2010@gmail.comwrites:
Quote:
When I use fread() to read a chunk of the file into a buffer, when it
encounters the end of the file, will the EOF indicator be put into the
buffer automatically just as an ordinary byte of the file, or do I
have to do it manually?
EOF is not a byte in a file and fread will not put it into a
buffer for you. Nor should you put it into the buffer yourself:
when converted to a character type, it will have the same value
as some other byte, so that later code will confuse that value
with an ordinary byte in the file.
Quote:
When I want to write chunks received to a new file, do I just write
each chunk sequentially until EOF? Do I need to append EOF to the new
file?
EOF is not a byte in a file and you cannot write it to a file.
You can try to write it to a file, but in fact you will just
write an ordinary byte, and thus I do not recommend trying.
Quote:
Suppose all chunks have been received and written to the new file,
then if I just name the new file with the correct extension, say
pic2.tif,will I be able to recover the original file like this?
You mean: if you copy the contents of one binary file accurately
to another, by using fread and fwrite, will the second file be
identical to the first? Ordinarily, yes: although I believe that
C allows the implementation to append any number of null bytes to
the second file, most implementations don't do that.
--
Comp-sci PhD expected before end of 2007
Seeking industrial or academic position *outside California* in 2008