Question #5639   Submitted by Answiki on 12/30/2021 at 09:00:38 AM UTC

What is the purpose of the getch() function in C?

Answer   Submitted by Answiki on 12/30/2021 at 09:02:07 AM UTC

The getch() function (getchar means get char) is used to read a character or a key from the keyboard. This function is blocking until the user presses a key. The character is not displayed on the screen. 


Here is an example of use:

#include <stdio.h>
#include <conio.h> // Pour la fonction getch()
 
int main()
{
   char ch;
   printf("Appuyez sur une touche pour continuer.\n"); 
   // Attend un appui sur une touche
   ch = getch();
   printf ("Vous avez appuyé sur la touche %c.\n", ch);
   return 0;
}


2 events in history
Answer by Answiki on 12/30/2021 at 09:02:07 AM

The getch() function (getchar means get char) is used to read a character or a key from the keyboard. This function is blocking until the user presses a key. The character is not displayed on the screen. 


Here is an example of use:

#include <stdio.h>
#include <conio.h> // Pour la fonction getch()
 
int main()
{
   char ch;
   printf("Appuyez sur une touche pour continuer.\n"); 
   // Attend un appui sur une touche
   ch = getch();
   printf ("Vous avez appuyé sur la touche %c.\n", ch);
   return 0;
}


Question by Answiki 12/30/2021 at 09:00:38 AM
What is the purpose of the getch() function in C?
# ID Query URL Count

Icons proudly provided by Friconix.