Re: feof(), fseek(), fread()
- From: Joe Wright <joewwright@xxxxxxxxxxx>
- Date: Sun, 25 Mar 2007 13:41:19 -0400
ericun*** wrote:
On 24 Mar, 01:40, Ben Pfaff <b...@xxxxxxxxxxxxxxx> wrote:Some part of your C education has been missed. First, EOF is a macro defined in stdio.h probably as.."ericun***" <xuwenduan2...@xxxxxxxxx> writes:If fseek() always clears EOF, is there a way for me to fread() from anPlease explain how the several previous answers to your several
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.
previous similar questions are inadequate.
--
"A lesson for us all: Even in trivia there are traps."
--Eric Sosman
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.
#define EOF (-1)
...It has a negative value of type int. You keep talking about fseek() clearing EOF. Wrong. Nothing about EOF can be cleared.
Within the file system there is there is presumably an indicator associated with the feof() function to tell us whether the file pointer (no, not FILE pointer) is at the end of the file. For sake of this discussion, let's call the flag eof (not EOF, which is a macro). This flag ivolves itself with attempts to read past the end of file with fgetc(), fgets(), etc. fseek() has nothing to do with reading from a file. There is nothing that fseek() can do that ought to set the eof flag.
If you would navigate within the file you can know its bounds (as offsets into the file) with two commands..
long eoff;
fseek(fp, 0, SEEK_END);
eoff = ftell(fp);
File offsets are now 0 to (not including) eoff, which is one past your playground. You can't seek past eoff. Attempts to do it will fail.
--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
.
- Follow-Ups:
- Re: feof(), fseek(), fread()
- From: Gordon Burditt
- Re: feof(), fseek(), fread()
- From: Keith Thompson
- Re: feof(), fseek(), fread()
- From: Walter Roberson
- Re: feof(), fseek(), fread()
- References:
- feof(), fseek(), fread()
- From: ericun***
- Re: feof(), fseek(), fread()
- From: Ben Pfaff
- Re: feof(), fseek(), fread()
- From: ericun***
- feof(), fseek(), fread()
- Prev by Date: Re: Uses of offsetof?
- Next by Date: Re: How to Return an array of strings in C (char**)
- Previous by thread: Re: feof(), fseek(), fread()
- Next by thread: Re: feof(), fseek(), fread()
- Index(es):