- get a string from a file

File Input/Output functions
(AFL 2.5)

SYNTAX fgets( filehandle )
FUNCTION The fgets function reads a string from the input file (defined by filehandle argument ) and returns it as a result.

fgets reads characters from the current file position to and including the first newline character, or to the end of the file whichever comes first. The newline character, if read, is included in the returned string.

The filehandle argument is a number returned by fopen function. The file has to be opened with "r" flag (for reading).

NOTE: fgets() reads maximum 1024 characters per line. Lines longer than that can be read using sequential calls to fgets() and "adding" (concatenating) results.

// The following code (commentary) reads
// all lines from the external file and
// displays it in commentary window

fh =
fopen( "quotes.csv", "r");
if( fh )
while( ! feof( fh ) )
printf( fgets( fh ) );   
printf("ERROR: file can not be found (does not exist)");

SEE ALSO fopen() function , fclose() function


The fgets function is used in the following formulas in AFL on-line library:

More information:

Updated on-line reference