Copyright (c) 1990 The Regents of the University of California.
All rights reserved.
This code is derived from software contributed to Berkeley by
Chris Torek.
%sccs.include.redist.man%
@(#)getc.3 6.4 (Berkeley) 01/20/91
All rights reserved.
This code is derived from software contributed to Berkeley by
Chris Torek.
%sccs.include.redist.man%
@(#)getc.3 6.4 (Berkeley) 01/20/91
GETC 3 ""
C 7 NAME
fgetc, getc, getchar, getw - get a character or word from a stream
SYNOPSIS
#include <stdio.h> int fgetc(FILE *stream); int getc(FILE *stream); int getchar() int getw(FILE *stream);
DESCRIPTION
Fgetc returns the next input character from the given
stream , or the next character pushed back via
ungetc . Getc acts essentially identically to fgetc , but is a macro that expands in-line.
Getchar is identical to ``getc(stdin)''.
Getw returns the next int from the named input stream .
"RETURN VALUE"
These functions return the integer constant
EOF at end-of-file, upon read error, or if an attempt is made to read a
write-only stream.
Callers must use
feof and
ferror to distinguish 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 . "SEE ALSO"
ferror(3), fread(3), fopen(3), putc(3), ungetc(3)
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.
Because it is implemented as a macro, getc treats a stream argument with side effects incorrectly. In particular, ``getc(*f++);'' may not work sensibly.
STANDARDS
Fgetc , getc and
getchar conform to ANSI X3.159-1989 (``ANSI C'').