getche()

getche() function reads a single character from the keyboard and displays immediately on the output screen without waiting for enter key. Like getch(), it is also a non-standard function present in <conio.h> header file.

Syntax

int getche(void);

Example

C




// Example for getche() in C
#include <conio.h>
#include <stdio.h>
int main()
{
    printf("%c", getche());
    return 0;
}


Input:  g(without enter key as it is not buffered)
Output: Program terminates immediately.
        But when you use DOS shell in Turbo C, 
        double g, i.e., 'gg'



Difference between getc(), getchar(), getch() and getche()

All of these functions read a character from input and return an integer value. The integer is returned to accommodate a special value used to indicate failure. The value EOF is generally used for this purpose.

Similar Reads

getc()

It reads a single character from a given input stream and returns the corresponding integer value (typically ASCII value of read character) on success. It returns EOF on failure....

getchar()

...

getch()

The difference between getc() and getchar() is getc() can read from any input stream, but getchar() reads a single input character from standard input. So getchar() is equivalent to getc(stdin)....

getche()

...