Posts 重写linux命令06_控制与信号
Post
Cancel

重写linux命令06_控制与信号

1. 终端模式小结

2.1 规范模式

有缓冲

2.2 非规范模式

无缓冲

2.3 raw模式

2. 编写 play——again

2.1 版本1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include	<stdio.h>
#include	<termios.h>

#define	QUESTION	"Do you want another transaction"
int get_resopnse(char *);
int main(){
    int response;
    response = get_resopnse(QUESTION);
    return response;

}

int get_resopnse(char *question){
    printf("%s (y/n)?" , question);
    while (1){
        switch (getchar()) {
            case 'y':
            case 'Y': return 0;
            case 'n':
            case 'N':
            case EOF: return 1;
        }
    }
}

存在问题:

  • 用户必须得按下回车键,程序才能运行
  • 程序接受整行处理

2.2 版本2

This post is licensed under CC BY 4.0 by the author.

Contents

Trending Tags