### _ungetch -- Push Character Back to Keyboard

Format

>     #include <conio.h>
>     int _ungetch(int c);

Language Level: Extension
_ungetch pushes the character c back to the keyboard, causing c to be the next character read. _ungetch fails if called more than once before the next read operation. The character c cannot be the EOF character.

Return Value
If successful, _ungetch returns the character c. A return value of EOF indicates an error.

Example
This example uses _getch to read a string delimited by the character 'x'. It then calls _ungetch to return the delimiter to the keyboard buffer. Other input routines can then process the delimiter.

    #include <conio.h>
    #include <stdio.h>

    int main(void)
    {
       int ch;
       printf("\nType in some letters.\n");
       printf("If you type in an 'x', the program ends.\n");
       for(;;) {
          ch = _getch();
          if ('x' == ch) {
             _ungetch(ch);
             break;
          }
          _putch(ch);
       }
       ch = _getch();
       printf("\n");
       printf("\nThe last character was '%c'.", ch);
       return 0;

       /***************************************************
          Here is the output from a sample run:

          Type in some letters.
          If you type in an 'x', the program ends.
          One Two Three Four Five Si
          The last character was 'x'.
       ***************************************************/
    }

_cscan -- Read Data From Keyboard
_getch - _getche -- Read Character from Keyboard
_putch -- Write Character to Screen
ungetc -- Push Character onto Input Stream
<conio.h>