Вы можете изменить программу так, чтобы она сразу реагировала на клавиатуру, т.е. не дожидаясь нажатия клавиши ввода.Это требует изменения свойств входного терминала и, как правило, более грязно и менее наглядно, чем линейно-ориентированный ввод. Эта страница описывает, как это сделать, и вот код, модифицированный для такой работы:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
struct termios saved_settings;
void
reset_term_mode(void)
{
tcsetattr (STDIN_FILENO, TCSANOW, &saved_settings);
}
int main()
{
tcgetattr(STDIN_FILENO, &saved_settings);
atexit(reset_term_mode);
struct termios term_settings;
tcgetattr(STDIN_FILENO, &term_settings);
term_settings.c_lflag &= ~(ICANON|ECHO);
term_settings.c_cc[VMIN] = 1;
term_settings.c_cc[VTIME] = 0;
tcsetattr(STDIN_FILENO, TCSAFLUSH, &term_settings);
char check = 'a';
char int_check = 'a';
int b = 0;
printf("want to go in? [y or n]\n");
scanf("%c",&check);
if ( check == 'y') {
while (1){
printf("Waiting: \n");
scanf("%c", &int_check);
if ( int_check == 'q'){
printf("You're out, bye!\n");
break;
};
};
} else if ( check == 'n'){
printf("You're not in, see ya!\n");
}else {
printf("Please, type 'y' or 'n'\n");
};
return 0;
}