fgets

Reads the characters in a file until hitting len of characters read, a new line or end of file if len is not provided.

Syntax

fgets(fileID)

fgets(fileID, request_length)

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

[text, actual_length] = fgets(fileID)

Inputs

fileID
The file ID returned from an earlier call to fopen(). stdin() cannot be used as a fileId. If it is required to get the input from stdin, input should be used.
Type: double | integer
request_length
Maximum number of characters to be read.
Type: double | integer

Outputs

text
String returned by fgets function.
actual_length
Number of characters returned by fgets function.

Example

Simple fgets example:

[fopen_fileID, fopen_msg] = fopen('testfile', 'r')
while feof(fopen_fileID) == false
	[fgets_return, fgets_length] = fgets(fopen_fileID)
	ftell_return = ftell(fopen_fileID)
end
fclose(fopen_fileID)
fopen_fileID = 5
fopen_msg = 
fgets_return = testoutput

fgets_length = 12
ftell_return = 12
ans = 0