Difference between revisions of "FGETS()"

From Lianjapedia
Jump to: navigation, search
 
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
==Purpose==
 
==Purpose==
 
Function to read and return a line of text from an ASCII file
 
Function to read and return a line of text from an ASCII file
 
  
 
==Syntax==
 
==Syntax==
 
FGETS(<expN1>[,<expN2>][,<expC>])
 
FGETS(<expN1>[,<expN2>][,<expC>])
 
  
 
==See Also==
 
==See Also==
 
[[FCLOSE()]], [[FCREATE()]], [[FEOF()]], [[FERROR()]], [[FFLUSH()]], [[FOPEN()]], [[FPUTS()]], [[FREAD()]], [[FREADSTR()]], [[FSEEK()]], [[FWRITE()]]
 
[[FCLOSE()]], [[FCREATE()]], [[FEOF()]], [[FERROR()]], [[FFLUSH()]], [[FOPEN()]], [[FPUTS()]], [[FREAD()]], [[FREADSTR()]], [[FSEEK()]], [[FWRITE()]]
 
  
 
==Description==
 
==Description==
 
The FGETS() function reads and returns a line of text from the file specified by <expN>, an ASCII file handle.  The file handle is returned from the FCREATE() or FOPEN() functions.  The FGETS() function reads a line of text from the current position of the record pointer.  You may optionally specify the number of bytes to read from that point with the numeric expression <expN2>.  The number of bytes may be from 0 to 254.  If a number is not specified, the FGETS() function will read 254 bytes or to the end line marker.  The optional character expression <expC> defines an end of line terminator to determine where the FGETS() function will stop reading.  The character expression <expC> must evaluate to one or two characters.
 
The FGETS() function reads and returns a line of text from the file specified by <expN>, an ASCII file handle.  The file handle is returned from the FCREATE() or FOPEN() functions.  The FGETS() function reads a line of text from the current position of the record pointer.  You may optionally specify the number of bytes to read from that point with the numeric expression <expN2>.  The number of bytes may be from 0 to 254.  If a number is not specified, the FGETS() function will read 254 bytes or to the end line marker.  The optional character expression <expC> defines an end of line terminator to determine where the FGETS() function will stop reading.  The character expression <expC> must evaluate to one or two characters.
 
  
 
==Example==
 
==Example==
Line 40: Line 36:
 
</code>
 
</code>
  
 
==Products==
 
Recital Server, Recital
 
 
[[Category:Documentation]]
 
[[Category:Documentation]]
 
[[Category:Functions]]
 
[[Category:Functions]]
[[Category:ASCII File Access]]
 
 
[[Category:ASCII File Access Functions]]
 
[[Category:ASCII File Access Functions]]

Latest revision as of 08:20, 4 February 2013

Purpose

Function to read and return a line of text from an ASCII file

Syntax

FGETS(<expN1>[,<expN2>][,<expC>])

See Also

FCLOSE(), FCREATE(), FEOF(), FERROR(), FFLUSH(), FOPEN(), FPUTS(), FREAD(), FREADSTR(), FSEEK(), FWRITE()

Description

The FGETS() function reads and returns a line of text from the file specified by <expN>, an ASCII file handle. The file handle is returned from the FCREATE() or FOPEN() functions. The FGETS() function reads a line of text from the current position of the record pointer. You may optionally specify the number of bytes to read from that point with the numeric expression <expN2>. The number of bytes may be from 0 to 254. If a number is not specified, the FGETS() function will read 254 bytes or to the end line marker. The optional character expression <expC> defines an end of line terminator to determine where the FGETS() function will stop reading. The character expression <expC> must evaluate to one or two characters.

Example

open database southwind
use example
fp=fcreate("names.txt")
count=0
do while not eof()
    count = count + fputs(fp,trim(last_name) + ", "+trim(first_name))
    skip
enddo
fclose(fp)
echo str(count,5) + " bytes written.\n"
 
fp = fopen("names.txt")
count = 0
do while not feof(fp)
    if left(fgets(fp),5) = "Smith"
        ++count
    endif
enddo
fclose(fp)
echo str(count,5) + " Smiths found.\n"
close databases