ungetch() Push Back the Last Character Read from the Console
#include <conio.h> Required for declarations only
int ungetch(c);
int c; Character to be pushed
ungetch() pushes back 'c', the last character read from the console.
'c' will then be the next character read. ungetch() can only be
called once between read statements.
Returns: The character 'c' if successful. A return value of EOF
indicates an error.
-------------------------------- Example ---------------------------------
The following statements get digits and alphabetic characters from
the console.
#include <conio.h>
#include <ctype.h>
char item[80];
char qty[5];
int x, y;
char ch;
main()
{
while (isdigit(ch = getche()))
qty[y++] = ch;
/* process 'qty' */
if (isalpha(ch))
ungetch(ch);
while (isalpha(ch = getche()))
item[x++] = toupper(ch);
/* process 'item' */
printf("\n%s %s\n",qty,item);
}
Seealso:
This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster