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 - fbwrite() write data to a binary file http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 fbwrite()           Write data to a binary file
------------------------------------------------------------------------------
 Declaration
   fileio.hdr

 Syntax
   func uint fbwrite extern
   param value _HFILE  hFile, ;
               untyped xBuffer, ;
         value uint    uBytes

 Arguments
   hFile is the handle of the file to manipulate.
   xBuffer is the buffer holding the data to be written to the file.
   uBytes is the number of bytes to write.

 Return
   The number of bytes written.

 Description
   The fbwrite() function attempts to write uBytes bytes to the
   file specified by hFile from the buffer xBuffer. It returns the
   number of bytes actually transferred. If fbwrite() returns a value
   different from the value specified in uBytes, then the disk is
   full or there is a physical defect with the file. It is most likely that
   the disk is full.

   The maximum value for uBytes is 65535 or 0xffff. The buffer
   xBuffer may represent any data type - char, dbl, logical, etc.. For
   example, you may use fbwrite() to write from a dbl array or a logical
   variable.

   As data is transferred to the file, DOS adjusts the read write pointer by
   uBytes bytes. So, if fbwrite() writes 20 bytes, the read write
   pointer of the file is adjusted by 20 bytes. Use fbseek() to move the
   read write pointer without reading or writing the file.

   The file must have been opened prior to the write unless the function
   call uses one of the predefined DOS file handles. DOS has five file
   handles that are predefined, that is, handles 0 through 4. These handles
   do not need to be opened. By using DOS predefined handles, you can write
   DOS filters.

   The header file fileio.hdr contains defines for the DOS file handles.
   Refer to the DOS handle table for more details.

 Example
   #define EXAMPLE_FILE
   #include example.hdr

   #pragma ESCSEQ+
   
   proc Test_fbwrite
   vardef
      _HFILE     hFile
      char( 20 ) cBuffer
      char( 2 )  cCRLF
      uint       nLine
   enddef
   cBuffer := space( 20 )
   cCRLF := "\r\n"
   nLine := 0
   if fbopen( hFile, "test.txt", FB_CWRITE )               // open file
      ? "Type some lines, finish with empty line"; ?
      repeat
         nLine++
         input "Line " + istr( nLine ) + ": " to cBuffer   // get a line
         fbwrite( hFile, cBuffer, len( cBuffer ) )         // write line
         fbwrite( hFile, cCRLF, len( cCRLF ) )             // add new line
      until isempty( cBuffer )
      fbclose( hFile )                                     // close file
      ? ; ? "File contents"; ?
      type "test.txt"                                      // display file
      ? ; wait
      erase "test.txt"                                     // clean up
   endif
   endproc

   proc main
   Test_fbwrite()
   endproc

See Also: DOS handle table fbread() fbseek() fbwriteln() fbwritep()

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