getc, getchar, fgetc, getw - get character or integer from stream
getc() returns the next character (that is, byte) from the named input
stream, as an integer. It also moves the file pointer, if defined,
ahead one character in stream. getchar() is defined as getc(stdin).
getc() and getchar() are macros.
fgetc() behaves like getc(), but is a function rather than a macro.
fgetc() runs more slowly than getc(), but it takes less space per invo-
cation and its name can be passed as an argument to a function.
getw() returns the next C int (word) from the named input stream.
getw() increments the associated file pointer, if defined, to point to
the next word. The size of a word is the size of an integer and varies
from machine to machine. getw() assumes no special alignment in the
On success, getc(), getchar() and fgetc() return the next character
from the named input stream as an integer. On failure, or on EOF, they
return EOF. The EOF condition is remembered, even on a terminal, and
all subsequent operations which attempt to read from the stream will
return EOF until the condition is cleared with clearerr() (see fer-
getw() returns the next C int from the named input stream on success.
On failure, or on EOF, it returns EOF, but since EOF is a valid inte-
ger, use ferror(3V) to detect getw() errors.
SYSTEM V RETURN VALUES
On failure, or on EOF, these functions return EOF. The EOF condition
is remembered, even on a terminal, however, operations which attempt to
read from the stream will ignore the current state of the EOF indica-
tion and attempt to read from the file descriptor associated with the
ferror(3V), fopen(3V), fread(3S), gets(3S), putc(3S), scanf(3V),
If the integer value returned by getc(), getchar(), or fgetc() is
stored into a character variable and then compared against the integer
constant EOF, the comparison may never succeed, because sign-extension
of a character on widening to integer is machine-dependent.
Because it is implemented as a macro, getc() treats a stream argument
with side effects incorrectly. In particular, getc(*f++) does not work
sensibly. fgetc() should be used instead.
Because of possible differences in word length and byte ordering, files
written using putw() are machine-dependent, and may not be readable
using getw() on a different processor.
21 January 1990 GETC(3V)