Reads a line of text from a file, retaining the newline (if present).
fh (scalar) – file handle of a file opened with
maxsize (scalar) – maximum size of string to read in, including the terminating null byte.
str (string) – Contains the text read from the file line specified by the file handle fh. The maximum size of the str, including the terminating null byte, is maxsize.
// Specify file name with full path fname = getGAUSSHome() $+ "examples/housing.csv"; // Open file handle for reading fh = fopen(fname, "r"); // Read the first line of the file // (up to 100 characters) s = fgets(fh, 100);
After the above code, s will equal:
// Read the second line of the file // by running 'fgets' again with the // same file handle. s = fgets(fh, 100);
After running the line above, s will be equal to:
fgets() procedure reads text from a file into a string. It reads up to a newline,
the end of the file, or \(maxsize-1\) characters. The result is placed in
str, which is then terminated with a null byte. The newline, if present,