NAME

getc, getchar, fgetc - get character or word from a stream

SYNOPSIS

#include <stdio.h>

int getc( FILE *stream );
int getchar(void);
int fgetc( FILE *stream );

DESCRIPTION

getc() returns the next character (that is, byte) from the named input stream as an unsigned char converted to an int. It also moves the file pointer, if defined, ahead one character in 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 argument to a function.

RETURN VALUES

These functions return the constant EOF at end-of-file or upon an error and set the EOF or error indicator of stream, respectively.

ERRORS

This function is a member of Unison's STDIO implementation. The STDIO implementation rests on top of IOLIB and inherits IOLIB's dependency on each specific server to report an appropriate error code for its usage.

For an exact list of error codes returned by a particular server, refer to that server's documentation in the Unison Programmer's Guide for each specific platform.

Servers may implement these errors codes in response to this function.

[EAGAIN]
The O_NONBLOCK flag is set for the file descriptor underlying stream and the thread would be delayed in the fgetc() operation.
[EBADF]
The file descriptor underlying stream is not a valid file descriptor open for reading.
[EIO]
This error may be generated for implementation-defined reasons.
[ENOMEM]
Insufficient storage space is available.
[ENXIO]
A request was made of a nonexistent device, or the request was outside the capabilities of the device.

SEE ALSO

fclose(), ferror(), fopen(), fread(), gets(), putc(), scanf(), ungetc()

NOTES

If the integer value returned by getc(), getchar(), 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 implementation dependent.

The macro version of getc() evaluates a stream argument more than once and may treat side effects incorrectly. In particular, getc(*f++) does not work sensibly. Use fgetc() instead.


< Copyright Rowebots Research Inc. and Multiprocessor Toolsmiths Inc. 1987-2011 >