This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Test for end-of-file


status = feof(fileID)


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.


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;

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced before R2006a

Was this topic helpful?