Skip to Main Content Skip to Search
Product Documentation

feof - Test for end-of-file

Syntax

status = feof(fileID)

Description

status = feof(fileID) returns 1 if a previous operation set the end-of-file indicator for the specified file. Otherwise, feof returns 0. fileID is an integer file identifier obtained from fopen.

Opening an empty file does not set the end-of-file indicator. Read operations, and the fseek and frewind functions, move the file position indicator.

Examples

Read bench.dat, which contains MATLAB benchmark data, one character at a time:

fid = fopen('bench.dat');

k = 0;
while ~feof(fid)
    curr = fscanf(fid,'%c',1);
    if ~isempty(curr)
       k = k+1;
       benchstr(k) = curr;
    end
end
    
fclose(fid);

See Also

fclose | ferror | fopen | frewind | fseek | ftell

How To

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS