totn C Functions

C Language: fgets function
(Read String from File)

In the C Programming Language, the fgets function reads characters from the stream pointed to by stream.

The fgets function will stop reading when n-1 characters are read, the first new-line character is encountered in s, or at the end-of-file, whichever comes first. Then the fgets function will append a null character to the string.

Syntax

The syntax for the fgets function in the C Language is:

char *fgets(char *s, int n, FILE *stream);

Parameters or Arguments

s
The array where the characters that are read will be stored.
n
The size of s.
stream
The stream to read.

Returns

The fgets function returns s. The fgets function will return a null pointer if an error occurs while trying to read the stream or the end of the stream is encountered before any characters are stored.

Required Header

In the C Language, the required header for the fgets function is:

#include <stdio.h>

Applies To

In the C Language, the fgets function can be used in the following versions:

  • ANSI/ISO 9899-1990

Similar Functions

Other C functions that are similar to the fgets function:

See Also

Other C functions that are noteworthy when dealing with the fgets function: