Admin Production ni-theme
Current Publication

fgets

LabWindows/CVI

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:
  • A newline character is read and retained.
  • An end-of-file is encountered after reading some characters.
  • (number_ofChars - 1) characters are read.
Note Note  If end-of-file is encountered and no characters have been read, the contents of this buffer remain unchanged. If a read error occurs, the contents of this buffer are indeterminate.

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

Examples

Refer to the following examples that use the fgets function:

  • dotnet\GenericList\genericlist.cws

    Open example
  • udp\DNSResolver.cws

    Open example
  • userint\custctrl\cviogl\ogldemo.cws

    Open example