主题 : pwm测试程序!有几句看不明白 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 8756
精华: 0
发帖: 34
金钱: 340 两
威望: 170 点
综合积分: 68 分
注册时间: 2009-09-05
最后登录: 2010-10-11
楼主  发表于: 2009-09-25 11:31

 pwm测试程序!有几句看不明白

struct termios oldt,newt;
    int ch;

    if (!isatty(STDIN_FILENO)) {
        fprintf(stderr, "this problem should be run at a terminal\n");
        exit(1);
    }
    // save terminal setting
    if(tcgetattr(STDIN_FILENO, &oldt) < 0) {
        perror("save the terminal setting");
        exit(1);
    }

    // set terminal as need
    newt = oldt;
    newt.c_lflag &= ~( ICANON | ECHO );
    if(tcsetattr(STDIN_FILENO,TCSANOW, &newt) < 0) {
        perror("set terminal");
        exit(1);
    }

    ch = getchar();

    // restore termial setting
    if(tcsetattr(STDIN_FILENO,TCSANOW,&oldt) < 0) {
        perror("restore the termial setting");
        exit(1);
    }
    return ch;

请问大家这几句是什么意思!帮我解释一下吧
为什么getchar()这前还要判断这么多东西呢!
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2009-09-25 11:43
用man + 你看不懂的函数名
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 8756
精华: 0
发帖: 34
金钱: 340 两
威望: 170 点
综合积分: 68 分
注册时间: 2009-09-05
最后登录: 2010-10-11
2楼  发表于: 2009-09-25 14:24
好办法!
  linux命令!
谢谢