[Previous]
[Contents]
[Next]

ungetch()

push a character back onto the input stream for the console

Synopsis:

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

Description:

The ungetch() function pushes the character specified by c back onto the input stream for the console. This character will be returned by the next read from the console (with getch() or getche() functions) and will be detected by the function kbhit(). Only the last character returned in this way is remembered.

The ungetch() function clears the end-of-file indicator, unless the value of c is EOF.

Returns:

The character pushed back.

Examples:

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

void main()
  {
    int c;
    long value;

    value = 0;
    c = getche();
    while( isdigit( c ) ) {
      value = value*10 + c - '0';
      c = getche();
    }
    ungetch( c );
    printf( "Value=%ld\n", value );
  }

Classification:

WATCOM

Safety:
Interrupt handler No
Signal handler No
Thread Yes

See also:

getch(), getche(), kbhit(), putch()


[Previous]
[Contents]
[Next]