GETC(S) UNIX System V GETC(S)
Name
getc, getchar, fgetc, getw - get character or word from a
stream
Syntax
#include <stdio.h>
int getc (stream)
FILE *stream;
int getchar ()
int fgetc (stream)
FILE *stream;
int getw (stream)
FILE *stream;
Description
The getc function 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.
The fgetc function behaves like getc, but is a function
rather than a macro. fgetc runs more slowly than getc, but
it takes less space per invocation and its name can be
passed as an argument to a function.
The getw function returns the next word (that is, integer)
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 file.
See Also
fclose(S), ferror(S), fopen(S), fread(S), gets(S), putc(S),
scanf(S), stdio(S)
Diagnostics
These functions return the constant EOF at end-of-file or
upon an error. Because EOF is a valid integer, ferror(S)
should be used to detect getw errors.
Warning
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.
Notes
Because it is implemented as a macro, getc evaluates a
stream argument more than once. 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 read using getw on a different processor.
Standards Conformance
fgetc, getc and getchar are conformant with:
AT&T SVID Issue 2, Select Code 307-127;
The X/Open Portability Guide II of January 1987;
ANSI X3.159-198X C Language Draft Standard, May 13,
1988;
IEEE POSIX Std 1003.1-1988 with C Standard Language-
Dependent System Support;
and NIST FIPS 151-1.
getw is conformant with:
AT&T SVID Issue 2, Select Code 307-127;
and The X/Open Portability Guide II of January 1987.
(printed 6/20/89)