プログラムを作成していて、何かキーが押されたらプログラムを終了したいです。これまでのところ、リターンが押された場合にのみそれを行うことができます。これは、ゲッチがリターンを押す必要があるためです。
コード:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
static void * breakonret(void *instance);
int main(){
pthread_t mthread;
pthread_create(&mthread, NULL, breakonret, NULL);
while(1){
printf("Data on screen\n");
sleep(1);
}
}
static void * breakonret(void *instance){
getchar();
exit(0);
}