[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feof(), ftell()
From: |
Daniel J Sebald |
Subject: |
feof(), ftell() |
Date: |
Tue, 21 Dec 2004 14:14:56 -0600 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20041020 |
I'm working on a block processing method where I read in data something
like:
while ~feof(fid)
and ran into some problems. It is easily fixed with some other tests.
However, the behavior of ftell() and feof() confused me a bit until I
figured out what was going on. Here is some sample code. Consider if
the results are a bit confusing.
fid = fopen('junk.dat', 'w+', 'ieee-le');
fwrite(fid, eye(2), 'int16');
fclose(fid);
fid = fopen('junk.dat', 'r+', 'ieee-le');
fseek(fid, 8, 'bof')
feof(fid)
ftell(fid)
fread(fid, 1, 'int16')
feof(fid)
ftell(fid)
fclose(fid);
fid = fopen('junk.dat', 'r+', 'ieee-le');
fseek(fid, 9, 'bof')
feof(fid)
ftell(fid)
fread(fid, 1, 'int16')
feof(fid)
ftell(fid)
fclose(fid);
What I find confusing is the last example. I realize that the fseek()
returns a -1, therefore THE RESULTS THAT FOLLOW DO NOT APPLY. However,
wouldn't it be possible for feof() to return a 1 if one positions the
pointer past the end of file? An 8 is past the end of the file. Why
should that be OK, but not 9? Also, ftell() wrapping around in the 9
example, is that confusing?
Thanks,
Dan
- octave warnings, John W. Eaton, 2004/12/01
- Re: octave warnings, Paul Kienzle, 2004/12/02
- Re: octave warnings, Daniel J Sebald, 2004/12/08
- Re: octave warnings, Dmitri A. Sergatskov, 2004/12/09
- legend in 2.1.64, Daniel J Sebald, 2004/12/12
- Re: legend in 2.1.64, Daniel J Sebald, 2004/12/12
- Re: legend in 2.1.64, David Bateman, 2004/12/13
- feof(), ftell(),
Daniel J Sebald <=