The getch() 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.Eventhough it does not echo the pressed character.
int getch(void);
The getch() function does not take any parameter.To store the input character in a program it has no any buffer area.
In getch() function the keyboard entered characters are returned as output.
Input | Return Value |
---|---|
if keypressed | pressed character |
#include <stdio.h>
#include <conio.h>
int main()
{
printf("Enter a key to exit the console screen.\n");
getch();
return 0;
}
Output:
Enter a key to exit the console screen.
#include <stdio.h>
#include <conio.h>
int main()
{
char ch;
printf(“Press any character: ”);
ch = getch();
printf(“\nPressed character is: %c”, ch);
}
Output:
Press any character: Pressed character is: a