Full prototype:

int ungetc(int, FILE*);  

Purpose and Notes:

Pushes the character passed in from the first argument passed in (int instead of char because of EOF) back onto the stream so that as long as fseek(), fsetpos() or rewind() are called on the stream that character will be the next one associated with any reads of the stream.

The standard only guarantees one call to ungetc on a stream in a row. Any other successive calls to ungetc may or may not work depending on the implementation.

Passing EOF back to the stream is not allowed and the stream will remain unchanged.

Clears any EOF indicators (if any) for the stream if successfully called.

For binary files a successfull call to the ungetc() function will set the file position indicator back one, but for text streams their position indicator is unspecified until all of the pushed back characters have been dealt with.


int- Returns the character passed back to the stream or EOF if the operation failed.

Argument 1:

int- The character to pass back to the stream.

Argument 2:

FILE*- The stream associated with the FILE pointer in which you want to push the character back onto.

Example 1