What is the difference between getch() and getche()?

Long Answer
Views 1727

Answer:

The getch() function reads a single character from the keyboard. It doesn't use any buffer, so entered data will not be displayed on the output screen.

The getche() function reads a single character from the keyword, but data is displayed on the output screen. Press Alt+f5 to see the entered character.

Let's see a simple example


#include<stdio.h>  
#include<conio.h>  
int main()  
{  
      
 char ch;  
 printf("Enter a character ");  
 ch=getch(); // taking an user input without printing the value.  
 printf("\nvalue of ch is %c",ch);  
 printf("\nEnter a character again ");  
 ch=getche(); // taking an user input and then displaying it on the screen.  
  printf("\nvalue of ch is %c",ch);  
 return 0;  
}  

Output:
Enter a character
value of ch is a
Enter a character again a
value of ch is a

In the above example, the value entered through a getch() function is not displayed on the screen while the value entered through a getche() function is displayed on the screen.

Related Articles:

This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of C Programming Language, click the links and dive deeper into this subject.

Join Our telegram group to ask Questions

Click below button to join our groups.