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

C Programming Language >   Overview of C Language >   First Program in C Hello World  

Long Question

1932


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.


This Particular section is dedicated to Question & Answer only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.




Join Our telegram group to ask Questions

Click below button to join our groups.