Name
getch, getche - Read a character.
Syntax
#include <conio.h>
int getch(void)
int getche(void)
Description
The getch function reads without echoing a single character
from standard input. The getche function reads a single
character from the console and echoes the character read.
Neither function can be used to read CTRL+C.
When reading a function key or cursor-moving key, the getch
and getche functions must be called twice; the first call
returns 0 or E0 (hexadecimal) and the second call returns
the actual key code.
Return Value
The getch function returns the character read. There is no
error return.
See Also
cgets(DOS), getchar(S), ungetch(DOS)
Example
#include <conio.h> #include <ctype.h>
int ch; main() {
printf("Input white space characters, followed");
printf(" by a non-white space character\n");
do ch = getch();
while (isspace(ch));
putch(ch); }
This program reads characters from the keyboard, but does
not echo them until it reads the first non-blank character.
(printed 6/18/89)