Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15374168
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类:

2009-11-05 16:45:10

《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$

阅读(1681) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~