I wanted just to implement this algorithm by C on Ubuntu:
wait for a certain time to receive input from keyboard, so, by getting possible input or by over time, the program should be continued.
I dont have any clue to do that! Thank you in advanced.
I wanted just to implement this algorithm by C on Ubuntu:
wait for a certain time to receive input from keyboard, so, by getting possible input or by over time, the program should be continued.
I dont have any clue to do that! Thank you in advanced.
See the manual for the alarm() and signal() functions. You can easily timeout any code without using any threads or processes.
The common way to do that is with select() or poll():
struct pollfd fd = {STDIN_FILENO, POLLIN};
switch(poll(&fd, 1, 1)){
case -1:
die("poll failed");
break;
case 0:
//timed out...
break;
default:
//read from stdin
}