Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - fopen() open a file as buffered file stream http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 fopen()             Open a file as buffered file stream
------------------------------------------------------------------------------
 Declaration
   fileio.hdr

 Syntax
   func logical fopen extern
   param       file fStream, ;
         const char cFileName, ;
         value int  iFileMode, ;
         value int  iAccessMode

 Arguments
   fStream is the file stream to manipulate.
   cFileName is the name of the file to open.
   iOpenMode is the file open mode.
   iAccessMode is the file access mode.

 Return
   A logical indicating if the file has been successfully opened.

 Description
   fopen() opens the file specified by cFileName as a buffered file stream.
   iFileMode specifies various modes (create, read, write, append), and
   iAccessMode defines if the file will be opened in text or in binary mode.
   See the Buffered file open table for open and access modes.

   Force supports up to 255 open files at one time by default. Use the
   morehandles() function to allocate more DOS file handles.

 Example
   #define EXAMPLE_FILE
   #include example.hdr

   proc Test_fopen
   vardef
      file    fTemp
      logical lSuccess
      char    cInput
   enddef
   // Open a text file for appending (i. e. the lines are added to the end of
   // the file). Create the file if it does not exist.
   lSuccess := fopen( fTemp, "test.txt", F_APPEND, F_TEXT )
   if .not. lSuccess
      lSuccess := fopen( fTemp, "test.txt", F_CREATE, F_TEXT )
   endif
   if lSuccess
      input "Type a line " to cInput     // get user input
      fwriteln( fTemp, cInput )          // write to file
      fclose( fTemp )                    // close file
      ? ; ? "Contents of file"
      type "test.txt"                    // display the file
   else
      ? "Unable to create file"
   endif
   endproc

   proc main
   Test_fopen()
   endproc

See Also: Buffered file open table fclose() fsetvbuf()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson