C getche()

The getche() function is defined in the conio.h header file. It is a character input function which holds the output screen untill the user passes any key from the keyboard and also echo the pressed character using direct video or BIOS.


int getche(void);  


getche() Parameters: 

The getche() function does not take any parameter.To store the input character in a program it has no any buffer area.

getche() Return Value

In getche() function the keyboard entered characters are returned as output.

Input Return Value
if keypressed pressed character

Examples of getche()

Example 1: Working of getche() function in C?


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

int main()  
{  
   char value;
   value = getche();
   printf("Enter any character : \n");
   printf("Entered character is : %c", value);
   return 0; 
}  

Output:


Enter any character : x
Entered character is : x

Example 2: How getche() works in C?


#include <stdio.h>
#include <conio.h>
int main()  
{
  char ch;
  printf(“Press any character: ”);
  ch = getche();
  printf(“\nPressed character is: %c”, ch);
}

Output:


Press any character: a 
Pressed character is: a