Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

fgets - get string from stream

&pagelevel(4)&pagelevel

Syntax

#include <stdio.h>

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

Description

fgets() reads at most n-1 bytes from the stream pointed to by stream until a newlinecharacter or an end-of-file condition is encountered. The string is read into the array pointed to by s and terminated with a null byte.

fgets() can mark the structure component st_atime for the file to which stream is assigned for changing (see sys/stat.h). The structure component st_atime is updated as soonas soon as fgetc(), fgets(), fgetwc(), fgetws(), fread(), fscanf(), getc(), getchar(), gets() or scanf() are called successfully for stream and return data which is not was not provided by a preceding call to ungetc() or ungetwc().

Return val.

Pointer to the result string


upon successful completion.

Null pointer

Null pointer

if the stream is at end-of-file. The end-of-file indicator for the stream is set.

if a read error occurs. The error indicator for the stream is set, and errno is set to indicate the error.

Errors

Notes

See fgetc().

The area in which fgets() is to store the string that is read must be supplied explicitly.

In contrast to gets(), fgets() also enters a newline character (if read) into the result string.

BS2000

The following applies in the case of text files with SAM access mode and variable record length for which a maximum record length is also specified: When the specification split=no was entered for fopen(), records of maximum length are not concatenated with the subsequent record when they are read. By default or with the specification split=yes, when a record with maximum record length is read, it is assumed that the following record is the continuation of this record and the records are concatenated (End).

The program environment determines whether fgets() is executed for a BS2000 or POSIX file.

See also

fgetc(), fopen(), fputs(), fread(), gets(), stdio.h, sys/stat.h.