fgetl
Reads one line from a file and drops the newline.
Category: Data Import and Analysis > Data Import and Export
Syntax
tline = fgetl(fid)
Returns the next line without its line terminator.
Description
Each call advances the read position by one line. Because the end is signalled by the number -1 rather than text, a loop that does not use feof can test ischar(tline). Use fgets instead to keep the newline.
Input arguments
fid- File identifier from
fopen.
Output arguments
tline- Character vector with the line, or the number
-1when the end of the file has been reached.
Example
Read lines until the end
fid = fopen('g.txt', 'w');
fprintf(fid, 'one\ntwo');
fclose(fid);
fid = fopen('g.txt');
a = fgetl(fid)
b = fgetl(fid)
c = fgetl(fid)
fclose(fid);
Output
a = 'one'
b = 'two'
c = -1