LabWindows/CVI

Content Type
Programming Language
Current manual

WriteFile

WriteFile

int WriteFile (int fileHandle, char buffer[], size_t count);

Purpose

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 function with the same name. Include windows.h before including formatio.h to ensure that there are no compilation errors as a result of this naming conflict. Define the SDK_CONFLICT_PRIORITYSDK_CONFLICT_PRIORITY macro to force LabWindows/CVI to use the Windows SDK implementation of this function.

Parameters

Input
Name Type Description
fileHandle int 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 char [] Specifies the buffer from which to write data.
count size_t 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.

An error is returned if you pass a value greater than INT_MAX.

Return Value

Name Type Description
bytesWritten int 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.

Note  If you opened the file in ASCII mode, the number of bytes returned does NOT include the CR characters that are inserted before LF characters when the data is written.

Additional Information

Library: Formatting and I/O Library

Include file: formatio.h

LabWindows/CVI compatibility: LabWindows/CVI 3.0 and later

Examples

Refer to the following examples that use the WriteFile function:

  • apps\atedemo\atedemo.cws

    Open example
  • apps\daqmthread\daqMT.cws

    Open example
Was this information helpful?