fgetl

Reads the characters in a file until hitting the request_length of characters read. Reads until a new line or end of file is encountered.

Syntax

fgetl(fileID)

fgetl(fileID, request_length)

[text, actual_length] = fgetl(fileID, request_length)

[text, actual_length] = fgetl(fileID)

Inputs

fileID
File ID returned from an earlier call to fopen().
Type: double | integer
request_length
Maximum number of characters to be read. Reading stops when a new line or end of file is encountered.
Type: double | integer

Outputs

text
Characters read from the file. fgetl() strips the trailing new line character from the text.
Type: double | integer
actual_length
Number of characters actually read from the file. This number does not include any new line character stripped by fgetl().
Type: double | integer

Example

% open file for writing
fileID = fopen('testfile', 'w+')
fprintf_result = fprintf(fileID, '%s\n', 'hello ')
fprintf_result = fprintf(fileID, '%s\n', 'world!')
fflush_result = fflush(fileID)
frewind_result = frewind(fileID)
% read the file back.  fgetl strips training new-line
while feof(fileID) == false
	printf('%s', fgetl(fileID))
end
printf('\n')
fclose_result = fclose(fileID)
fileID = 6
fprintf_result = 7
fprintf_result = 7
fflush_result = 0
frewind_result = 0
hello world!
fclose_result = 0