Question

The manual for the standard c library function fseek says: "A successful call to the fseek()function clears the end-of-file indicator for the stream."

To me it sounds like saying if EOF is at 2 and I call fseek() to get the pointer at 4, that should work and eof will be now pointing to 5. But when I test this hypothesis, the pointer doesn't advance beyond current EOF(2 in above case), and hence my understanding of the line is wrong. What does this line mean then? Thanks!

Was it helpful?

Solution

You have to remember that the EOF flag is not set until you actually try to read from beyond the end of the file.

With fseek clearing the flag, it does this even if you seek to beyond the end of the file. And it works because the flag will be set again next time you read.

That is why it's a bad idea to have loops such as while (!feof(...)), as those will then loop once to many without detecting the actual end of the file condition.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top