Difference between revisions of "FPUTS()"

From Recital Documentation Wiki
Jump to: navigation, search
Line 23: 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(first) + trim(last))
+
     count = count + fputs(fp,trim(first_name) + ", "+trim(last_name))
 
     skip
 
     skip
 
enddo
 
enddo
dialog box str(count,5) + "written."
+
fclose(fp)
 +
dialog box str(count,5) + " bytes written."
 +
close databases
 
</code>
 
</code>
  

Revision as of 12:57, 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(first_name) + ", "+trim(last_name))
    skip
enddo
fclose(fp)
dialog box str(count,5) + " bytes written."
close databases


Products

Recital Server, Recital