Re: feof(), fseek(), fread()



"ericunfuk" <xuwenduan2010@xxxxxxxxx> writes:
On 24 Mar, 01:40, Ben Pfaff <b...@xxxxxxxxxxxxxxx> wrote:
"ericunfuk" <xuwenduan2...@xxxxxxxxx> writes:
If fseek() always clears EOF, is there a way for me to fread() from an
offset of a file and still be able to detect EOF?i.e. withouting using
fseek(). I also need to seek to an offset in the file
frequently(forwards and backwards) and do fread() from that offset.

Please explain how the several previous answers to your several
previous similar questions are inadequate.

I still don't know how can I detect EOF while I'm always use fseek()
(It always clears EOF), and I must be able to seek forwards and
backwards in the file, but I still don't know up to now how can I do
this without fseek(), that's why I posted this question.

Please don't quote signatures.

You keep talking about clearing EOF. What you really mean is clearing
the end-of-file indicator for a stream. EOF is something different
(even though it's an abbreviation of End Of File).

The end-of-file indicator indicates that the last attempt to read from
the file failed because you attempted to read past the end of the
file. The way to detect this is to check the result of whatever
function you're using to read from the file. If you use fread()
(which is perfectly reasonable), check the value it returns; if it
tells you that it read fewer items than you asked it to, then you've
probably reached the end of the file.

It's also possible that there's been an error of some sort; the
ferror() function can tell you this.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <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"
.



Relevant Pages

  • Re: feof(), fseek(), fread()
    ... offset of a file and still be able to detect EOF?i.e. ... this without fseek(), that's why I posted this question. ... EOF is a macro defined in stdio.h probably as.. ... eoff = ftell; ...
    (comp.lang.c)
  • Re: reading file
    ... Does fseek() clears the EOF if I don't move beyond EOF? ... A more correct statement of your question is: ... Does fseekclear the end-of-file indicator if I don't move beyond ...
    (comp.lang.c)
  • Re: feof(), fseek(), fread()
    ... offset of a file and still be able to detect EOF? ... You can do it with fseek, ... "Debugging is twice as hard as writing the code in the first place. ...
    (comp.lang.c)
  • Re: fseek() clears EOF?
    ... When the documentation says "fseek() clears EOF indecator, ... character in the file, not when you read the last character. ... the end-of-file indicator, but that's less useful than you might ...
    (comp.lang.c)
  • Re: Determining EOF using fseek()?
    ... I was wondering if it was possible to determine if you hit 'EOF' using ... I'm using fseek to traverse through the file from start to end ... In Unix it's entirely legal to fseek, or lseek, ... each check, and compare. ...
    (comp.lang.c)