fgetst

Purpose

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

Format

str = fgetst(fh, maxsize)
Parameters:
  • fh (scalar) – file handle of a file opened with fopen().

  • maxsize (scalar) – maximum size of string to read in, including the null terminating byte.

Returns:

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.

Examples

 // 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:

"taxes","beds","baths","new","price","size"
// 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:

3104,4,2,0,279.9,2048

Remarks

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()