Difference between revisions of "FGETS()"

From Recital Documentation Wiki
Jump to: navigation, search
 
Line 17: Line 17:
 
==Example==
 
==Example==
 
<code lang="recital">
 
<code lang="recital">
 +
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")
 
fp = fopen("names.txt")
 
count = 0
 
count = 0
do while not feof()
+
do while not feof(fp)
     if fgets(fp,20) = "Smith"
+
     if left(fgets(fp),5) = "Smith"
 
         ++count
 
         ++count
 
     endif
 
     endif
 
enddo
 
enddo
 +
fclose(fp)
 +
echo str(count,5) + " Smiths found.\n"
 +
close databases
 
</code>
 
</code>
  

Latest revision as of 13:14, 25 January 2010

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


Products

Recital Server, Recital