C Language: ungetc function(Unread Character)

In the C Programming Language, the ungetc function puts a character back onto the stream pointed to by stream and clears the end-of-file indicator for stream.


The syntax for the ungetc function in the C Language is:

int ungetc(int c, FILE *stream);


The character to put back onto the stream.


The stream to modify.


The ungetc function returns the character that is put back. If an error occurs because too many attempts are made to put back characters without a read or file positioning operation, the ungetc function will return EOF.

Required Header

In the C Language, the required header for the ungetc function is:

#include <stdio.h>

Applies To

In the C Language, the ungetc function can be used in the following versions:

  • ANSI/ISO 9899-1990

stdio.h Functions