I have a problem with pthread_create
. I would like to make a thread to track the keyboard button, eg when I press the spacebar the program aborts the main loop.
Here is my code (create a thread):
void check_button_code(int *btn);
// main
pthread_t trd;
int btn = 1;
pthread_create(&trd,NULL,check_button_code, &btn);
Action to break
void check_button_code(int *btn) {
int a;
printf("Press space to pause\n.");
while (1) {
a = getchar();
if (a == 32) {
*btn = 0;
break;
} else {
printf("error %d\n", a);
}
}
printf("zatrzymane\n");
}
Thank you in advance for your help.