Single Character Input Function : getche()

Single Character Input Function : getche()

getche() is used to get a character from console, and echoes to the screen.


int getche(void);

Example Declaration:

char ch;

ch = getche();


getche reads a single character from the keyboard and echoes it to the current text window, using direct video or BIOS.

Return Value:

This function return the character read from the keyboard.

getche() Example Program:

// Header Files

void main()
   char ch;
   ch = getche();
   printf("Input Char Is :%c",ch);


Program Explanation:

Here,declare the  variable ch as  char data type, and then get a value through getche()library function and store it in the variable ch.And then,print the value of variable ch.

During the program execution, a single character is get or read through the getche(). The given value is displayed on the screen and the compiler does not wait for another character to be typed. Then,after wards the character is  printed  through the  printf function.