Monday, April 7, 2014

getch Function in C C Language


Function Name: getch()   
Function Header:  <CONIO.H>
Declaration int getch(void)
Return Value: This function returns the character read from the keyboard.

Notes

The function getch() gets a character from console but does not echo to the screen. getch() reads a single character directly from the keyboard, without echoing to the screen. For this functionality we can use this function to hold output window until hit any key from keyboard.

Example

#include <conio.h>
#include <stdio.h>

{
  int c;
  printf(“Press any key
”);
  c = getch();
  if (c)
    printf(“ A key is pressed from keyboard ”);
  else
    printf(“An error occurred ”);
  getch()
}

Output

How it works

After running this program, when we press any key from keyboard we’ll see the next line but won’t see the key which is pressed. For the last getch() function, the output window will be held until press any key from keyboard.


Related Posts by Categories

0 comments:

Post a Comment