A program gets the input from the user and does some kind of processing on that data and outputs the result. Input and Output functions are the links between the user and the terminal. In C programming language, there are number of input functions and output functions provided by the language. Two such functions are getch and getche. The key difference between getch and getche is that, getch is used to read a single character from the keyboard which does not display the entered value on screen and does not wait for the enter key whereas getche is used to read a single character from the keyboard which displays immediately on screen without waiting for the enter key. This article discusses the difference between the two functions getch and getche.
CONTENTS
1. Overview and Key Difference
2. What is getch
3. What is getche
4. Similarities Between getch and getche
5. Side by Side Comparison – getch vs getche in Tabular Form
6. Summary
What is getch?
getch is used to read a single character from the keyboard. The reading does not display on the screen. The entered character is immediately returned without waiting for the enter key.
getch will read the user entered value but it does not display that on the screen. When the user gives an input character, it does not display on the screen and without waiting for the enter key, the output of printf is displayed to the screen on the next position. It only displays because of the printf function.
According to the above program, a character is read using getch function. It does not display the received value on the screen and does not wait till the enter key is pressed. Here, the input character ‘y’ is given. It does not display on the screen and does not wait till the enter key is pressed. The ‘y’ value is displayed because of the putchar function.
What is getche?
getche function is used to read a single character from the keyboard. The reading is displayed immediately on the screen without waiting for the enter key.
According to the above program, a character is read using getche function. It displays the received value on the screen. It does not wait till the enter key is pressed. When giving the input ‘a’, it is displayed on the screen. It does not wait till the enter key is pressed. The second ‘a’ value is displayed on the screen because of the putchar function.
What are the Similarities Between getch and getche?
- Both are functions provided by the C language.
- Does not wait till the enter key is pressed.
What is the Difference Between getch and getche?
getch vs getche |
|
getch is a C function to read a single character from the keyboard which does not display on screen and immediately returned without waiting for the enter key. | getche is a C function to read a single character from the keyboard which displays immediately on screen without waiting for the enter key. |
Input Displaying Method | |
getch does not display the character entered by the user. | getche displays the character entered by the user. |
Syntax | |
getch syntax is similar to int getch(void); | getche syntax is similar to int getche(void); |
Summary – getch vs getche
getch and getche are functions in C language. The difference between getch and getche is that, getch is used to read a single character from the keyboard which does not display the entered value on screen and does not wait for the enter key ; getche is used to read a single character from the keyboard which displays immediately on screen without waiting for the enter key. The getch and getche appear to be same but they are different.
Download the PDF Version of getch vs getche
You can download PDF version of this article and use it for offline purposes as per citation note. Please download PDF version here Difference Between getch and getche
Reference:
- mahajancomputerskkr. YouTube, YouTube, 31 Jan. 2014. Available here
- Ashim Lamichhane, Project Manager at Kath Codex Follow. “Unit 3. Input and Output.” LinkedIn SlideShare, 29 Feb. 2016. Available here