GETC(3) BSD Programmer's Manual GETC(3)NAME
fgetc, getc, getc_unlocked, getchar, getchar_unlocked, getw - get next
character or word from input stream
SYNOPSIS
#include <stdio.h>
int
fgetc(FILE *stream);
int
getc(FILE *stream);
int
getc_unlocked(FILE *stream);
int
getchar(void);
int
getchar_unlocked(void);
int
getw(FILE *stream);
DESCRIPTION
The fgetc() function obtains the next input character (if present) from
the stream pointed at by stream, or the next character pushed back on the
stream via ungetc.
The getc() function acts identically to fgetc().
The getchar() function is equivalent to getc() with the argument stdin.
The getw() function obtains the next int (if present) from the stream
pointed at by stream.
The getc_unlocked() and getchar_unlocked() are equivalent to getc() and
getchar() respectively except that they are expanded in-line and are not
implemented in a thread-safe manner. They are intended for use with
flockfile() and funlockfile() which provide thread-safe synchronization.
RETURN VALUES
If successful, these routines return the next requested object from the
stream. If the stream is at end-of-file or a read error occurs, the rou-
tines return EOF. The routines feof(3) and ferror(3) must be used to dis-
tinguish between end-of-file and error. If an error occurs, the global
variable errno is set to indicate the error. The end-of-file condition
is remembered, even on a terminal, and all subsequent attempts to read
will return EOF until the condition is cleared with clearerr.
Note that EOF is negative, while input characters returned by the getc()
family of functions are first strained through the unsigned char type, so
that EOF is distinct from all possible input characters. Storing the re-
turn value in a char variable will lose this distinction, however, and
should therefore be done only after comparison against EOF.
SEE ALSOferror(3), fread(3), fopen(3), putc(3), ungetc(3), pthreads(3),
flockfile(3), funlockfile(3)STANDARDS
The fgetc(), getc() and getchar() functions conform to ANSI C X3.159-1989
(``ANSI C '').
The getc_unlocked and getchar_unlocked functions conform to IEEE
Std1003.1c (``POSIX'').
BUGS
Since EOF is a valid integer value, feof and ferror must be used to check
for failure after calling getw(). The size and byte order of an int
varies from one machine to another, and getw() is not recommended for
portable applications.
BSDI BSD/OS June 4, 1993 2