FUNCTION REFERENCE

fgets

Read one line of a file and keep the line break.

Read one line of a file and keep the line break.

Syntax

tline = fgets(fid)

Syntax

tline = fgets(fid, nchar)

Syntax

[tline, ltout] = fgets(fid)

Returns -1 when there is nothing left to read. Lines end as for fgetl; ltout is

the terminator (LF, CR LF or CR).

Example

fid = fopen('data.txt'); fgetl(fid); l = fgets(fid)   % '2,4' and a line break

Differences from MATLAB: same as fgetl.

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.