getc

Full prototype:

int getc(FILE*);  

Purpose and Notes:

A function that returns the next character (as an int so it can also return EOF) from the file stream pointed to by the FILE* passed in as the only argument. The function returns EOF under three circumstances: if the EOF indicator is set for the file. If the next character in the stream is the end of the stream and thus sets off the EOF indicator itself. Or if there is an error reading from the stream.

The only difference between getc() and fgetc() is that the argument passed in SHOULD NEVER BE AN EXPRESSION. This is because it may be implemented as a macro that might evaluate it multiple times. So make sure that it is a FILE* and nothing else!

Returns:

int- The next character in the file stream passed in by the FILE* argument. Stored as an int as it will return the EOF (which is beyond the ASCII codes and thus requires an int to store) if the end of the file is reached, EOF is set for the stream, or an error occured reading from the stream.

Argument 1:

FILE*- A pointer to a file stream to read in one character.

Example 1