getc(3S) getc(3S)NAME getc, getchar, fgetc, getw - get character or word from a stream SYNOPSIS #include <stdio.h> int getc(stream) FILE *stream; int getchar() int fgetc(stream) FILE *stream; int getw(stream) FILE *stream; DESCRIPTION The getc macro 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. The getchar macro is defined as getc(stdin). fgetc behaves like getc, but is a function rather than a macro. fgetc runs more slowly than getc, but takes less space per invocation and its name can be passed as an argu- ment to a function. getw returns the next word (32-bit integer on a Macintosh II) from the named input stream. getw increments the asso- ciated file pointer, if defined, to point to the next word. getw assumes no special alignment in the file. RETURN VALUE These functions return the constant EOF at end-of-file or upon an error. Because EOF is a valid integer, ferror(3S) should be used to detect getw errors. SEE ALSO fclose(3S), ferror(3S), fopen(3S), fread(3S), gets(3S), putc(3S), scanf(3S), ungetc(3S). WARNINGS 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. April, 1990 1
getc(3S) getc(3S)BUGS Because it is implemented as a macro, getc treats incorrect- ly a stream argument with side effects. In particular, getc(*f++) does not work sensibly. fgetc should be used in- stead. Because of possible differences in word length and byte ord- ering, files written using putw are machine-dependent, and may not be read using getw on a different processor. 2 April, 1990