getche() Library Functions with Examples

Like getch(), getche() is also character input functions. It is unformatted input function meaning it does not allow user to read input in their format. Difference between getch() and getche() is that getche() echoes pressed character. getche() also returns character pressed like getch(). It is also defined in header file conio.h.

getche() Syntax


character_variable = getche();

getche() Examples

Example #1 : Reading Character Using getche() & Displaying


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

void main()
{
  char ch;
  printf(“Press any character: ”);
  ch = getche();
  printf(“\nPressed character is: %c”, ch);
}

Output of the above program :

Press any character: e
Pressed character is: e

-----------------------------------
Note: while using getch() pressed 
character is not echoed but while 
using getche() it is echoed. Here pressed 
character is e and it is displayed 
by printf().