《linux下如何从terminal终端tcsetattr立即得到输入字符,而不等待回车键》/*
* Copyright (c) 2009 Luther Ge
*/
#include
#include
#include
int main(void)
{
struct pollfd pfds;
int retval;
char str[256];
memset(&pfds, 0, sizeof(pfds));
pfds.fd = 0;
pfds.events = POLLIN;
retval = poll(&pfds, 1, 2*1000);
if (pfds.revents & POLLIN) {
fscanf(stdin, "%s", str);
printf("=========\ninput string is : %s\n", str);
} else {
printf("timeout : %d, %x\n", retval, pfds.revents);
}
}
luther@gliethttp:/vobs/tmp$ ./a.out
HelloWorld!
=========
input string is : HelloWorld!
luther@gliethttp:/vobs/tmp$ ./a.out
timeout : 0, 0
luther@gliethttp:/vobs/tmp$
阅读(1722) | 评论(0) | 转发(0) |