JavaScript Editor js editor     Web development 

Main Page

Returns a series of bytes from a file or a communication port opened with a low-level file function until it encounters a carriage return.

FGETS(nFileHandle [, nBytes])



Specifies the numeric file handle of the file or communication port from which FGETS(В ) returns data.

Specifies the number of bytes FGETS(В ) returns. FGETS(В ) returns nBytes bytes unless a carriage return is encountered first. FGETS(В ) returns data between the starting file-pointer position and the carriage return if a carriage return is encountered within nBytes bytes. FGETS(В ) returns a maximum of 8192 bytes. If you omit nBytes, FGETS(В )returns 254 bytes by default.

Return Value



You can read a file line by line by issuing a series of FGETS(В ).

FGETS(В ) returns a series of bytes as a character string. Data is returned starting from the current file's pointer position and continuing until a carriage return is encountered. The file pointer is then positioned on the byte immediately following the carriage return. The carriage return is not returned as part of the string, and line feeds are discarded.


В Copy Code
*** TEST.TXT must exist ***
STORE FOPEN('test.txt') TO gnFileHandle    && Open the file
STORE FSEEK(gnFileHandle, 0, 2) TO gnEnd    && Move pointer to EOF
STORE FSEEK(gnFileHandle, 0) TO gnTop     && Move pointer to BOF
IF gnEnd <= 0  && Is file empty?
   WAIT WINDOW 'This file is empty!' NOWAIT
ELSE  && If not
   gcString = FGETS(gnFileHandle, gnEnd)  && Store contents
   ? gcString
= FCLOSE(gnFileHandle)  && Close the file

See Also

JavaScript Editor js editor     Web development