All rights reserved.
This code is derived from software contributed to Berkeley by
Chris Torek.
%sccs.include.redist.man%
@(#)fgets.3 6.5 (Berkeley) 01/20/91
#include <stdio.h> char * fgets(char *str, size_t size, FILE *stream); char * gets(char *str);
Gets is equivalent to fgets with an infinite size and a stream of stdin , except that the newline character (if any) is not stored in the string. It is the caller's responsibility to ensure that the input line, if any, is sufficiently short to fit in the string.
Upon successful completion, fgets and gets return s . If end-of-file or an error occurs before any characters are read, they return NULL. Callers must use feof and ferror to determine which occurred.
15 [EBADF] Stream is not a readable stream.
Fgets may also fail and set errno for any of the errors specified for the routines fflush (3), fstat (2), read (2), or malloc (3).
Gets may also fail and set errno for any of the errors specified for the routine getchar (3).