From maintainers-request at octave dot org Tue Dec 21 14:11:12 2004 Subject: feof(), ftell() From: Daniel J Sebald To: octave maintainers mailing list Date: Tue, 21 Dec 2004 14:14:56 -0600 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