Main Content

feof

Test for end of file

Description

status = feof(fileID) returns a 1 if the end of the file specified by fileID was reached by a previous operation. Otherwise, feof returns a 0.

example

Examples

collapse all

From this badpoem.txt file, read one line at a time to the end of the file.

Use fopen to open the file. This function assigns a unique file id to use for reading and writing to the file.

fid = fopen('badpoem.txt');

Read and display one line at a time until you reach the end of the file.

while ~feof(fid)
    tline = fgetl(fid);
    disp(tline)
end
Oranges and lemons,
Pineapples and tea.
Orangutans and monkeys,
Dragonflys or fleas.

Close the file.

fclose(fid);

Input Arguments

collapse all

File identifier of an open file, specified as an integer. Before testing for the end-of-file status, you must use fopen to open the file and obtain its identifier fileID.

Data Types: double

Tips

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

Extended Capabilities

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

Version History

Introduced before R2006a

expand all