Difference between revisions of "FOPEN()"

From Lianjapedia
Jump to: navigation, search
m (1 revision)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
==Purpose==
 
==Purpose==
 
Function to open an existing ASCII text file or http URL
 
Function to open an existing ASCII text file or http URL
 
  
 
==Syntax==
 
==Syntax==
 
FOPEN(<expC> [,expN>])
 
FOPEN(<expC> [,expN>])
 
  
 
==See Also==
 
==See Also==
[[FCREATE()]], [[FCLOSE()]], [[FEOF()]], [[FERROR()]], [[FFLUSH()]], [[FGETS()]], [[FPUTS()]], [[FREAD()]], [[FREADSTR()]], [[FSEEK()]], [[FWRITE()]], [[GETURL()]], [[MEMOREAD()]], [[MEMOWRITE()]], [[TEXTEDIT()]]
+
[[FCREATE()]], [[FCLOSE()]], [[FEOF()]], [[FERROR()]], [[FFLUSH()]], [[FGETS()]], [[FPUTS()]], [[FREAD()]], [[FREADSTR()]], [[FSEEK()]], [[FWRITE()]], [[GETURL()]], [[MEMOREAD()]], [[MEMOWRITE()]]
 
+
  
 
==Description==
 
==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:
 
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" width="100%"
{| class="wikitable"
+
!width="20%"|<expN>||Access Mode
!<expN>||Access Mode
+
 
|-
 
|-
 
|||If not specified, read-only
 
|||If not specified, read-only
Line 24: Line 20:
 
|1||Write only.  Existing contents are deleted.
 
|1||Write only.  Existing contents are deleted.
 
|-
 
|-
|2||Append.  Text may be added to the end of the existing contents.
+
|valign="top"|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().
 
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().
 
'''Recital 10 enhancements'''
 
  
 
The FOPEN() function can also be used to open http page URLs.  The specified <expC> is the URL to open: http://twitter.com/recitalsoftware.  Please see below for an example.
 
The FOPEN() function can also be used to open http page URLs.  The specified <expC> is the URL to open: http://twitter.com/recitalsoftware.  Please see below for an example.
  
 
The FOPEN() function can also be used to open Linux FIFO pipes.  The specified <expC> is the pipe to open: fifo://pipename.
 
The FOPEN() function can also be used to open Linux FIFO pipes.  The specified <expC> is the pipe to open: fifo://pipename.
 
  
 
==Example==
 
==Example==
Line 66: Line 58:
 
     ? fgets(fp)
 
     ? fgets(fp)
 
enddo
 
enddo
 +
fclose(fp)
 
%>
 
%>
 
</body>
 
</body>
Line 71: Line 64:
 
</code>
 
</code>
  
 
==Products==
 
Recital, Recital Server
 
 
[[Category:Documentation]]
 
[[Category:Documentation]]
 
[[Category:Functions]]
 
[[Category:Functions]]
[[Category:ASCII File Access]]
 
 
[[Category:ASCII File Access Functions]]
 
[[Category:ASCII File Access Functions]]

Latest revision as of 06:16, 22 October 2013

Purpose

Function to open an existing ASCII text file or http URL

Syntax

FOPEN(<expC> [,expN>])

See Also

FCREATE(), FCLOSE(), FEOF(), FERROR(), FFLUSH(), FGETS(), FPUTS(), FREAD(), FREADSTR(), FSEEK(), FWRITE(), GETURL(), MEMOREAD(), MEMOWRITE()

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().

The FOPEN() function can also be used to open http page URLs. The specified <expC> is the URL to open: http://twitter.com/recitalsoftware. Please see below for an example.

The FOPEN() function can also be used to open Linux FIFO pipes. The specified <expC> is the pipe to open: fifo://pipename.

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  
 
// http URL example
<!-- twitter.rsp -->
<html>
<body>
<%
fp=fopen("http://twitter.com/recitalsoftware")
do while not feof(fp)
    ? fgets(fp)
enddo
fclose(fp)
%>
</body>
</html>