匿名 #7026(2008/08/07 00:29 GMT) [ C ] Rating0/0=0.00
手抜きです。Unix likeなシステム限定です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> #include <sys/types.h> #include <unistd.h> void cleanup(void) { system("stty sane"); putc('\n', stderr); } int waitfor(int fd, int secs) { fd_set fds; struct timeval tv = { secs, 0 }; FD_ZERO(&fds); FD_SET(fd, &fds); return select(fd + 1, &fds, 0, 0, secs > 0 ? &tv : 0); } int main(void) { int c = 0, timeout = 1; system("stty raw"); atexit(cleanup); while (c != 'q') if (!waitfor(fileno(stdin), timeout)) putc('a', stderr); else if ((c = getchar()) == 'p') timeout *= -1; return 0; }
Rating0/0=0.00-0+
[ reply ]
匿名
#7026()
[
C
]
Rating0/0=0.00
Rating0/0=0.00-0+
[ reply ]