|
|
原代码如下:
- #include <stdio.h>
- #include <termios.h>
- #include <unistd.h>
- #include <stdlib.h>
- #define MESSAGE "play again?[y/n]"
- int do_show(char *);
- void set_tty();
- void tty_mode(int);
- struct termios term_temp,term_chg;
- int main()
- {
- int i = 1;
- while(i){
- i = do_show(MESSAGE);
- }
- return i;
- }
- int do_show(char *str)
- {
- while(1){
- printf("%s",str);
- switch(getchar()){
- case 'y':;
- case 'Y':return 0;
- case 'n':;
- case 'N':;
- default:return 1;
- }
- }
- }
- void set_tty()
- {
- tcgetattr(0,&term_chg);
- [color=Red] term_chg =term_chg & ~ECHO;
- term_chg =term_chg & ~ICANON;
- term_chg.c_cc[VMIN] = 1;
- [/color]
- tcsetattr(0,TCSANOW,&term_chg);
- }
- void tty_mode(int i)
- {
- if(i = 0)
- tcgetattr(0,&term_temp);
- else
- tcsetattr(0,TCSANOW,&term_temp);
- }
复制代码
用gcc编译的时候,居然提示红色部分invalid operands to binanry &,这是为何呢? |
|