FPUTS()

From Recital Documentation Wiki
Revision as of 13:13, 25 January 2010 by Yvonnemilne (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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