Difference between revisions of "FSOCKOPEN()"
Yvonnemilne (Talk | contribs) |
Yvonnemilne (Talk | contribs) |
||
Line 4: | Line 4: | ||
fp = fsockopen(address as character, port as numeric) as numeric | fp = fsockopen(address as character, port as numeric) as numeric | ||
( use fputs(), fgets(), fflush(), fread(), fclose() with this function ) | ( use fputs(), fgets(), fflush(), fread(), fclose() with this function ) | ||
+ | |||
+ | |||
+ | ==Purpose== | ||
+ | Function to open an existing ASCII text file | ||
+ | |||
+ | |||
+ | ==Syntax== | ||
+ | FOPEN(<expC> [,expN>]) | ||
+ | |||
+ | |||
+ | ==See Also== | ||
+ | [[FCLOSE()]], [[FFLUSH()]], [[FGETS()]], [[FPUTS()]], [[FREAD()]] | ||
+ | |||
+ | |||
+ | ==Description== | ||
+ | The FOPEN() function opens an existing ASCII text file. It returns a numeric file pointer when the file is opened successfully, or a -1 if unsuccessful. The <expC> is the name of the ASCII file to open. Since the file pointer is required to identify an open file to other file functions, always assign the return value to a memory variable. The optional <expN> determines the file access mode: | ||
+ | |||
+ | |||
+ | {| class="wikitable" | ||
+ | !<expN>||Access Mode | ||
+ | |- | ||
+ | |||If not specified, read-only | ||
+ | |- | ||
+ | |0||Read-only | ||
+ | |- | ||
+ | |1||Write only. Existing contents are deleted. | ||
+ | |- | ||
+ | |2||Append. Text may be added to the end of the existing contents. | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | |||
+ | If an error occurs, -1 is returned by the FERROR() function. The FCLOSE() function is used to close a file which has been opened with FOPEN(). | ||
+ | |||
+ | |||
+ | ==Example== | ||
+ | <code lang="recital"> | ||
+ | use accounts | ||
+ | fp=fopen("existing.file") | ||
+ | if ferror()=-1 | ||
+ | dialog box "The file could not be opened." | ||
+ | else | ||
+ | string = fgets(fp) | ||
+ | do while not empty(string) | ||
+ | ? string | ||
+ | string = fgets(fp) | ||
+ | enddo | ||
+ | ? | ||
+ | endif | ||
+ | fclose(fp) | ||
+ | if ferror()=-1 | ||
+ | dialog box "The file could not be closed." | ||
+ | endif | ||
+ | </code> | ||
+ | |||
+ | ==Products== | ||
+ | Recital, Recital Server | ||
+ | [[Category:Documentation]] | ||
+ | [[Category:Functions]] | ||
+ | [[Category:ASCII File Access]] | ||
+ | [[Category:ASCII File Access Functions]] |
Revision as of 11:51, 1 December 2009
TCP/IP socket function fp = fsockopen(address as character, port as numeric) as numeric ( use fputs(), fgets(), fflush(), fread(), fclose() with this function )
Purpose
Function to open an existing ASCII text file
Syntax
FOPEN(<expC> [,expN>])
See Also
FCLOSE(), FFLUSH(), FGETS(), FPUTS(), FREAD()
Description
The FOPEN() function opens an existing ASCII text file. It returns a numeric file pointer when the file is opened successfully, or a -1 if unsuccessful. The <expC> is the name of the ASCII file to open. Since the file pointer is required to identify an open file to other file functions, always assign the return value to a memory variable. The optional <expN> determines the file access mode:
<expN> | Access Mode |
---|---|
If not specified, read-only | |
0 | Read-only |
1 | Write only. Existing contents are deleted. |
2 | Append. Text may be added to the end of the existing contents. |
If an error occurs, -1 is returned by the FERROR() function. The FCLOSE() function is used to close a file which has been opened with FOPEN().
Example
use accounts fp=fopen("existing.file") if ferror()=-1 dialog box "The file could not be opened." else string = fgets(fp) do while not empty(string) ? string string = fgets(fp) enddo ? endif fclose(fp) if ferror()=-1 dialog box "The file could not be closed." endif
Products
Recital, Recital Server