ReadLine
int ReadLine (int fileHandle, char lineBuffer[], ssize_t maximumBytes);
Purpose
Reads bytes from a file until it encounters a linefeed (LF) and places up to maximum#Bytes bytes, excluding the LF, into a buffer. If the number of bytes read exceeds a specified maximum, ReadLine discards the excess bytes so that the buffer does not overflow.
![]() |
Note ReadLine adds an ASCII NUL byte at the end of the bytes read. |
Parameters
Input | ||||
Name | Type | Description | ||
fileHandle | int | Specifies the file from which the line is to be read. Call OpenFile to obtain fileHandle. Open the file in ASCII mode so that ReadLine treats a carriage return/linefeed (CR/LF) combination as an LF. If fileHandle is zero, ReadLine reads the line from the Standard I/O window. |
||
maximumBytes | ssize_t | Maximum number of bytes, excluding the ASCII NUL, to read into the line. Once ReadLine reaches the maximum, it discards bytes until it reads an LF. If you enter –1 into this control, then no maximum will be applied. The function returns an error if you pass a value greater than INT_MAX.
|
||
Output | ||||
Name | Type | Description | ||
lineBuffer | char [] | Specifies the variable where the line is to be stored. This variable must be large enough to contain maximum#Bytes bytes plus an ASCII NUL. |
Return Value
Name | Type | Description |
bytesRead | int | Number of bytes ReadLine reads from the file, including discarded bytes, but excluding LF. Hence, the return value exceeds maximum#Bytes if bytes are discarded. If ReadLine reads no bytes because it has already reached the end of the file, it returns –2. If an I/O error occurs, possibly because of a bad file handle, ReadLine returns –1. You can use GetFmtIOError to get more information about the type of error that occurred. A value of 0 indicates that ReadLine read an empty line. |
Additional Information
Library: Formatting and I/O Library
Include file: formatio.h
LabWindows/CVI compatibility: LabWindows/CVI 3.0 and later