Difference between revisions of "FPUTS()"
Yvonnemilne (Talk | contribs) |
Yvonnemilne (Talk | contribs) |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | |||
− | |||
− | |||
− | |||
==Purpose== | ==Purpose== | ||
Function to write a character string to an ASCII file | Function to write a character string to an ASCII file | ||
Line 27: | Line 23: | ||
==Example== | ==Example== | ||
<code lang="recital"> | <code lang="recital"> | ||
+ | open database southwind | ||
+ | use example | ||
fp=fcreate("names.txt") | fp=fcreate("names.txt") | ||
count=0 | count=0 | ||
do while not eof() | do while not eof() | ||
− | count= count + fputs(fp,trim( | + | count = count + fputs(fp,trim(last_name) + ", "+trim(first_name)) |
skip | skip | ||
enddo | 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 | ||
</code> | </code> | ||
==Products== | ==Products== | ||
− | Recital | + | Recital Server, Recital |
[[Category:Documentation]] | [[Category:Documentation]] | ||
[[Category:Functions]] | [[Category:Functions]] | ||
+ | [[Category:ASCII File Access]] | ||
+ | [[Category:ASCII File Access Functions]] |
Latest revision as of 13:13, 25 January 2010
Purpose
Function to write a character string to an ASCII file
Syntax
FPUTS(<expN1>,<expC1>[,<expN2>][,<expC2>])
See Also
FCLOSE(), FCREATE(), FEOF(), FERROR(), FFLUSH(), FGETS(), FOPEN(), FREAD(), FSEEK(), FWRITE()
Description
The FPUTS() function writes the specified character string to an ASCII file that was created by the FCREATE() function, or opened with the FOPEN() function. The numeric expression <expN1> is the file handle returned by either the FCREATE() or FOPEN() functions, and is used to specify the file that the FPUTS() function writes to.
The character expression <expC1> is the character string that FPUTS() will write to the file. The character string will be placed at the current position of the file pointer. After the string is written to the file, the file pointer is repositioned past the last character of <expC1>.
The FPUTS() function will terminate <expC1> with a default carriage return/line feed on OpenVMS, and a line feed on UNIX/Linux. You may optionally specify a different terminator with character expression <expC2>. Character expression <expC2> must evaluate to one or two characters. The optional numeric expression <expN2> specifies the number of bytes that the FPUTS() function will write from <expC1>. This number must be between 0 and 254.
The FPUTS() function returns the number of bytes, including the end of line terminator, that was written to the file. The FPUTS() function will return a zero if the write was unsuccessful.
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