FGETS
Section: C Library Functions (3)
Index
Return to Main Contents
BSD mandoc
NAME
fgets
gets
- get a line from a stream
SYNOPSIS
Fd #include <stdio.h>
Ft char *
Fn fgets char *str size_t size FILE *stream
Ft char *
Fn gets char *str
DESCRIPTION
The
Fn fgets
function
reads at most one less than the number of characters specified by
size
from the given
Fa stream
and stores them in the string
Fa str .
Reading stops when a newline character is found,
at end-of-file or error.
The newline, if any, is retained.
In any case a
`\0'
character is appended to end the string.
The
Fn gets
function
is equivalent to
Fn fgets
with an infinite
size
and a
Fa 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.
RETURN VALUES
Upon successful completion,
Fn fgets
and
Fn gets
return
a pointer to the string.
If end-of-file or an error occurs before any characters are read,
they return
NULL.
The
Fn fgets
and
functions
Fn gets
do not distinguish between end-of-file and error, and callers must use
feof(3)
and
ferror(3)
to determine which occurred.
ERRORS
- Bq Er EBADF
-
The given
Fa stream
is not a readable stream.
The function
Fn 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).
The function
Fn gets
may also fail and set
errno
for any of the errors specified for the routine
getchar(3).
SEE ALSO
feof(3),
ferror(3),
fgetln(3)
STANDARDS
The functions
Fn fgets
and
Fn gets
conform to
St -ansiC .
BUGS
Since it is usually impossible to ensure that the next input line
is less than some arbitrary length, and because overflowing the
input buffer is almost invariably a security violation, programs
should
NEVER
use
Fn gets .
The
Fn gets
function
exists purely to conform to
St -ansiC .
Index
- NAME
-
- SYNOPSIS
-
- DESCRIPTION
-
- RETURN VALUES
-
- ERRORS
-
- SEE ALSO
-
- STANDARDS
-
- BUGS
-
This document was created by
man2html,
using the manual pages.
Time: 15:52:51 GMT, January 15, 2023