GETS(3S) — UNIX Programmer’s Manual
NAME
gets, fgets − get a string from a stream
SYNOPSIS
#include <stdio.h>
char ∗gets(char ∗s);
char ∗fgets(char ∗s, int n, FILE ∗stream);
DESCRIPTION
Gets reads a string into s from the standard input stream stdin, until end-of-file is encountered or a new-line character is read. The string is terminated by a newline character, which is replaced in s by a null character.
Fgets reads n−1 characters, or up through a newline character, whichever comes first, from the stream into the string s. No additional characters are read after a new-line character (which is retained) or after end-of-file. The last character read into s is followed by a null character.
RETURN VALUE
Fgets and gets returns s if successful. If unsuccessful, a null pointer is returned and an error code is stored in errno.
ERRORS
The underlying function of fgets and gets is read(2). The error conditions specified for read(2) apply to fgets and gets.
SEE ALSO
read(2), puts(3S), getc(3S), scanf(3S), fread(3S), ferror(3S)
DIAGNOSTICS
Gets and fgets return the constant pointer NULL upon end of file or error.
BUGS
Gets deletes a newline, fgets keeps it, all in the name of backward compatibility.
ANSI C — August 1, 1992