Write to an open binary file

     FWRITE(<nHandle>, <cBuffer>, [<nBytes>])
        --> nBytesWritten


     <nHandle> is the file handle obtained from FOPEN(), FCREATE(), or
     predefined by DOS.

     <cBuffer> is the character string to write to the specified file.

     <nBytes> indicates the number of bytes to write beginning at the
     current file pointer position.  If omitted, the entire content of
     <cBuffer> is written.


     FWRITE() returns the number of bytes written as an integer numeric
     value.  If the value returned is equal to <nBytes>, the operation was
     successful.  If the return value is less than <nBytes> or zero, either
     the disk is full or another error has occurred.


     FWRITE() is a low-level file function that writes data to an open binary
     file from a character string buffer.  You can either write all or a
     portion of the buffer contents.  Writing begins at the current file
     position, and the function returns the actual number of bytes written.

     If FWRITE() results in an error condition, FERROR() can be used to
     determine the specific error.

     Warning!  This function allows low-level access to DOS files and
     devices.  It should be used with extreme care and requires a thorough
     knowledge of the operating system


     .  This example copies the contents of one file to another:

        #include "Fileio.ch"
        #define F_BLOCK      512
        cBuffer := SPACE(F_BLOCK)
        nInfile := FOPEN("Temp.txt", FO_READ)
        nOutfile := FCREATE("Newfile.txt", FC_NORMAL)
        lDone := .F.
        DO WHILE !lDone
           nBytesRead := FREAD(nInfile, @cBuffer, F_BLOCK)
           IF FWRITE(nOutfile, cBuffer, nBytesRead) < ;
              ? "Write fault: ", FERROR()
              lDone := .T.
              lDone := (nBytesRead == 0)

 Files   Library is CLIPPER.LIB.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.