You are here

getche in C

getche function prompts the user to press a character and that character is printed on the screen.

C code for getche

  1. #include<stdio.h>
  2. #include<conio.h>
  3.  
  4. main()
  5. {
  6.    printf("Waiting for a character to be pressed from the keyboard to exit.");
  7.  
  8.    getche();
  9.    return 0;
  10. }

Run this program and press a character. Then view the user screen (Alt+F5) if using Turbo C compiler. You will find the character printed on the screen if you pressed a printable character. Try pressing enter or tab key (non-printable) characters also.