Reads a line of text from a file without retaining the newline.


str = fgetst(fh, maxsize)
  • fh (scalar) – file handle of a file opened with fopen().
  • maxsize (scalar) – maximum size of string to read in, including the null terminating 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 = fgetst(fh, 100);

After the above code, s will equal:

// Read the second line of the file
// by running 'fgets' again with the
s = fgetst(fh, 100);

After running the line above, s will be equal to:



The fgetst() procedure operates identically to fgets(), except that the newline is not retained in the string.

In general, you don’t want to use fgetst() on files opened in binary mode (see fopen()). The fgetst() procedure drops the newline, but it does NOT drop the preceding carriage return used on some platforms. Printing out such a string can produce unexpected results.

See also

Functions fgets(), fgetsat(), fopen()