Borland C++ reference

ungetch

raw OCR

Pushes a character back to the keyboard buffer.

Defined in header <conio.h>

Syntax

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

Portability

DOSUNIXWindowsANSI CC++ only
■■

Remarks

ungetch pushes the character ch back to the console, causing ch to be the next character read. The ungetch function fails if it is called more than once before the next read.

Return value

ungetch returns the character ch if it is successful. A return value of EOF indicates an error.

See also

Example

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

int main(void)
{
   int i=0;
   char ch;
   puts("Input an integer followed by a char:");

   /* read chars until nondigit or EOF  */
   while ((ch = getcheO)  != EOF && isdigit(ch))
      i = 10 * i + ch - 48;       /* convert ASCII into int value V

   /* if nondigit char was read, push  it back into input buffer */
   if (ch != EOF)
      ungetch(ch);
   printf("\n\ni - %d, next char in buffer  = %c\n", i, getchO);
   return 0;

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.