gisty 20.07.2011 20:02 GajimAA0AE356

while(1)
{
fd_set rfds;
struct timeval tv;
int retval;
/* Watch stdin (fd 0) to see when it has input. */
FD_ZERO(&rfds);
FD_SET(0, &rfds);
/* Wait up to five seconds. */
tv.tv_sec = 0;
tv.tv_usec = 50000;
/* Don't rely on the value of tv now! */
if (retval = select(1, &rfds, NULL, NULL, &tv))
{
printf("Data is available now.\n");
putchar(getc(stdin));
//FD_ISSET(0, &rfds) will be true.
usleep(50000);
} else
printf("No data within one seconds.\n");
}
----
вот так вот считывать ввод пользоватея риалтайм, без блокирования выполнения программы. пойду теперь в змейку это применять, лол

Recommended by: @proton
Do you really want to delete ?