2
I would like to stop the programme by pressing ESC at any time, as would be possible?
2
I would like to stop the programme by pressing ESC at any time, as would be possible?
0
With the use of the function getch
you can pick up the character that was typed on the console, in which case the number 27 represents the keyboard ESC.
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int main()
{
char opcao;
while(opcao != 27)
{
printf("\n\n\nEscolha uma opcao:\n");
printf("<esc> para sair\n\n");
opcao = getch();
if (opcao != 27)
{
printf("Voce nao apertou ESC\n\n");
}
}
return 0;
}
Browser other questions tagged c
You are not signed in. Login or sign up in order to post.
Additional note: To
conio.h
is Platform-dependent.– Gabriel
How would getch be "optional"? If I press nothing, it simply executes the next function. If I press, it aborts the program anywhere in it. Thank you
– Maycon