Next: Formatted Output, Previous: Simple Output, Up: C-Style I/O Functions
To read from a file it must be opened for reading using fopen.
Then a line can be read from the file using fgetl as the following
code illustrates
fid = fopen ("free.txt");
txt = fgetl (fid)
-| Free Software is needed for Free Science
fclose (fid);
This of course assumes that the file `free.txt' exists and contains the line `Free Software is needed for Free Science'.
Read characters from a file, stopping after a newline, or EOF, or len characters have been read. The characters read, excluding the possible trailing newline, are returned as a string.
If len is omitted,
fgetlreads until the next newline character.If there are no more characters to read,
fgetlreturns −1.See also: fread, fscanf.
Read characters from a file, stopping after a newline, or EOF, or len characters have been read. The characters read, including the possible trailing newline, are returned as a string.
If len is omitted,
fgetsreads until the next newline character.If there are no more characters to read,
fgetsreturns −1.See also: fread, fscanf.