LabWindows/CVI

Content Type
Programming Language
Current manual

ReadFile

ReadFile

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

Purpose

Reads up to count bytes of data from a file or the Standard Input into buffer. Reading starts at the current position of the file pointer. When ReadFile completes, the file pointer points to the next unread character in the file.

The return value can be less than the number of bytes requested if ReadFile reaches the end of the file before the byte count is satisfied. If you open the file in ASCII mode, ReadFile counts each carriage return/linefeed (CR/LF) combination read as one character because the pair is translated into an LF when ReadFile stores it in the buffer.

Note  ReadFile does not terminate the buffer with an ASCII NUL.
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 The file from which to read the data. Call OpenFile to obtain a fileHandle. To read from the Standard I/O window, pass 0 for fileHandle.
count size_t Maximum number of bytes to read. count must not be greater than buffer size.

An error is returned if you pass a value greater than INT_MAX.
Output
Name Type Description
buffer char [] Buffer into which you read data. You must allocate space for this buffer before you call ReadFile.

Return Value

Name Type Description
bytesRead int Number of bytes read.

A value of –1 indicates that an error occurred during the read operation, possibly because of a bad file handle. You can use GetFmtIOError to get more information about the type of error that occurred.

A return value of 0 indicates that ReadFile did not read any bytes because it reached the end of the file.

Note  If you opened the file in ASCII mode, the number of bytes returned does NOT include the CR in a CR/LF combination because each CR/LF combination is translated to an LF when the data is read.

Additional Information

Library: Formatting and I/O Library

Include file: formatio.h

LabWindows/CVI compatibility: LabWindows/CVI 3.0 and later

Was this information helpful?

Previous

CloseFile

Previous

CloseFile

Help us improve your future ni.com experience.

What are you trying to do?

Submit