fgetsat#

Purpose#

Reads lines of text from a file into a string array without retaining newlines.

Format#

sa = fgetsat(fh, numl)#
Parameters:
  • fh (scalar) – file handle of a file opened with fopen().

  • numl (scalar) – number of lines to read.

Returns:

sa (Nx1 string array) – Contains the text read from the file lines specified by the file handle fh. \(N <= numl\).

Examples#

// Specify file name with full path
fname = getGAUSSHome("examples/housing.csv");

// Open file handle for reading
fh = fopen(fname, "r");

// Read the first 3 lines of the file
s = fgetsat(fh, 3);

After the above code, s will equal:

"taxes","beds","baths","new","price","size"
3104,4,2,0,279.9,2048
1173,2,1,0,146.5,912

Note that s will NOT have a newline character at the end of each line.

Remarks#

The fgetsat() procedure operates identically to fgetsa(), except that newlines are not retained as text is read into sa.

In general, you don’t want to use fgetsat() on files opened in binary mode (see fopen()). The fgetsat() procedure drops the newlines, but it does NOT drop the carriage returns that precede them on some platforms. Printing out such a string array can produce unexpected results.

See also

Functions fgetsa(), fgetst(), fopen()