在网上找到的一个关于feof的解释,和C standard有关。
FEOF follows the ANSI C standard that says it does not return true until you read past the end of the file
我的理解是feof实际上是判断fid有没有越过文件结束位。fseek(fid,0,'eof')只是把fid指向了文件结束位并没有越过,所以这个时候foef返回0.如果要feof返回1,就必须要在feof之前调用fread,fgetl之类的命令,让fid越过文件结束位一次。
判断文件是否读完还可以用这个方法,matlab里也提到了
while 1
tline = fgetl(fid);
if ~ischar(tline), break, end
disp(tline)
en