fgets
char *fgets (char lineBuffer[], int numberOfChars, FILE *stream);
Purpose
Reads characters from the specified input stream into a lineBuffer until end-of-file is encountered, a newline character is read, or (number_ofChars - 1) characters are read. The newline character is retained. An ASCII NUL byte is appended to the end of the string. If successful, the function returns a pointer to lineBuffer.
Parameters
Input | ||||
Name | Type | Description | ||
numberOfChars | int | Specifies the maximum number of characters to write to lineBuffer including the terminating ASCII NUL byte. If neither a newline character is read nor an end-of-file is encountered, the function reads (number_ofCharacters - 1) characters from the specified file. | ||
stream | FILE * | Contains a pointer to the input stream from which a line of data is read. | ||
Output | ||||
Name | Type | Description | ||
lineBuffer | char [] |
Contains the address of the buffer that receives the line of characters
read in from the specified input stream. The following conditions append an ASCII NUL byte to the buffer and
stop the function:
|
Return Value
Name | Type | Description |
returnedLineBuffer | char * | Contains the returned result of the function. If successful, the function returns a pointer to the NUL-terminated string of characters. If the function encounters end-of-file and reads no characters into the lineBuffer, it returns a NULL pointer. If a read error occurs, fgets returns NULL and sets errno to a nonzero value. |
Additional Information
Library: ANSI C Library
Include file: ansi_c.h
LabWindows/CVI compatibility: LabWindows/CVI 3.0 and later