Keil Logo


#include <stdio.h>

int ungetchar (
  int c);   /* character to unget */

The ungetchar function stores the character c back into the input stream. The next call to getchar or any other stream input function returns c. Only one character may be passed to unget between calls to getchar.

Return Value

The ungetchar function returns the character c if successful. If ungetchar is called more than once between function calls that read from the input stream, EOF is returned indicating an error condition.

See Also

_getkey, getchar, putchar

#include <stdio.h>
#include <ctype.h>  /* for isdigit */

void tst_ungetchar (void) {
  int k;

  while (isdigit (k = getchar ())) {
    /* stay in the loop as long as k is a digit */

  ungetchar (k);
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.