"ericunfuk" <xu***********@gmail.comwrites:
Also, a question about fseek().
Does fseek() clears the EOF if I don't move beyond EOF?
What is "the EOF", and what does "beyond EOF" mean?
A more correct statement of your question is:
Does fseek() clear the end-of-file indicator if I don't move beyond
the end of the file?
The answer is yes. C99 7.19.9.2p5 says:
After determining the new position, a successful call to the fseek
function undoes any effects of the ungetc function on the stream,
clears the end-of-file indicator for the stream, and then
establishes the new position.
But why do you care? The end-of-file indicator is set by an attempt
to read past the end of the file. 99% of the time, the correct way to
detect this is to look at the value returned by whatever function you
just used to read from the file; fgetc() returns the value EOF,
fread() returns a number of records smaller than the number you
requested, and so on.
Your system should have documentation that explains all
of this. If you're on a Unix-like system, "man fseek"
should have the answer to your question. For other systems,
the way to read the documentation will vary. And if you're
ambitious, the latest draft of the C standard is available at
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf>; it's
not easy reading, but the index and table of contents are good,
and it has the definitive description of the language and of all the
standard library functions.
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"