Re: feof(), fseek(), fread()
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Fri, 23 Mar 2007 19:43:24 -0700
"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"
.
- References:
- feof(), fseek(), fread()
- From: ericunfuk
- Re: feof(), fseek(), fread()
- From: Ben Pfaff
- Re: feof(), fseek(), fread()
- From: ericunfuk
- feof(), fseek(), fread()
- Prev by Date: Re: feof(), fseek(), fread()
- Next by Date: Re: feof(), fseek(), fread()
- Previous by thread: Re: feof(), fseek(), fread()
- Next by thread: Re: feof(), fseek(), fread()
- Index(es):
Relevant Pages
|