Table of Contents
Previous Section Next Section

ungetc

#include <stdio.h>int ungetc(int ch, FILE *stream);

The ungetc( ) function returns the character specified by the low-order byte of ch to the input stream stream. This character will then be obtained by the next read operation on stream. A call to fflush( ), fseek( ), or rewind( ) undoes an ungetc( ) operation and discards the character.

A one-character pushback is guaranteed; however, some implementations will accept more.

You may not unget an EOF.

A call to ungetc( ) clears the end-of-file flag associated with the specified stream. The value of the file position indicator for a text stream is undefined until all pushed-back characters are read, in which case it will be the same as it was prior to the first ungetc( ) call. For binary streams, each ungetc( ) call decrements the file position indicator.

The return value is equal to ch on success and EOF on failure.

A related function is getc( ).


Table of Contents
Previous Section Next Section