C Programming/stdio.h/fgetc

From Wikibooks, open books for an open world
Jump to navigation Jump to search

The fgetc function in the C standard library stdio.h is used to read a character from a file stream.

int fgetc(FILE *stream)

Where FILE *stream is an initialised pointer to a file.

If successful, fgetc returns a character from the file at its current position. If unsuccessful, fgetc returns an error code. For text files (as opposed to binary files), the characters with values 25 and 26 (the substitute character and the escape character) may render the input stream inoperable afterward, instead returning a single maximal value.

Error codes:

-1: Bad argument: not integer
-2: Bad argument: out of range
-3: File was not open

References[edit | edit source]