GETC(3S) DOMAIN/IX SYS5 GETC(3S)
NAME
getc, getchar, fgetc, getw - get character or word from a stream
USAGE
#include <stdio.h>
int getc(stream)
FILE *stream;
int getchar()
int fgetc(stream)
FILE *stream;
int getw(stream)
FILE *stream;
DESCRIPTION
Getc returns the next character (i.e., 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 invocation, and its name can be passed as an argu-
ment to a function.
Getw returns the next word (i.e., 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.
NOTES
Because it is implemented as a macro, getc treats a stream
argument with side effects incorrectly. In particular
getc(*f++)
can cause problems. Use fgetc instead.
Because of possible differences in word length and byte ord-
ering, files written using putw are machine-dependent.
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 the sign-extension of a character upon widening to
Printed 12/4/86 GETC-1
GETC(3S) DOMAIN/IX SYS5 GETC(3S)
integer is also machine-dependent.
DIAGNOSTICS
These functions return the constant EOF at end-of-file or
upon an error. Because EOF is a valid integer, you should
use ferror(3S) to detect getw errors.
RELATED INFORMATION
fclose(3S), ferror(3S), fopen(3S), fread(3S), gets(3S),
putc(3S), scanf(3S)
GETC-2 Printed 12/4/86