int WriteFile (int fileHandle, char *buffer, unsigned int count);
Writes up to count bytes of data from buffer to a file or to the Standard Output. WriteFile starts writing at the current position of the file pointer. When WriteFile completes, it increments the file pointer by the number of bytes written.
For files you open in ASCII mode, WriteFile replaces each linefeed (LF) character with a carriage return/linefeed (CR/LF) combination in the output. The return value does not include the CR characters WriteFile inserts before the LF characters.
![]() |
Caution The Windows SDK also contains a WriteFile function. If you include windows.h and do not include formatio.h, you will get compile errors if you call WriteFile. |
Input | ||
Name | Type | Description |
fileHandle | integer | Specifies the file to which the data is written. To write data to a file, first call OpenFile to obtain a fileHandle. To write to the Standard Output, pass 1 for fileHandle. Open the file in ASCII mode so that a CR will be written before each LF. |
buffer | string | Specifies the buffer from which to write data. |
count | integer | Number of bytes to write. count overrides the buffer size in determining the number of bytes to write. Buffers that contain embedded ASCII NUL bytes are written in full. count must not be greater than buffer size. |
Name | Type | Description | ||
n | integer | Number of bytes written to the file. A value of –1 indicates that an error occurred during the write operation. An error can indicate a bad file handle, an attempt to access a protected file, an attempt to write to a file opened as read only, or that there is no more space left on disk. You can use GetFmtIOError to get more information about the type of error that occurred.
|