3 回答
TA贡献1848条经验 获得超2个赞
stty
#include<stdio.h>int main(void){ int c; /* use system call to make terminal send all keystrokes directly to stdin */ system ("/bin/stty raw"); while((c=getchar())!= '.') { /* type a period to break out of the loop, since CTRL-D won't work raw */ putchar(c); } /* use system call to set terminal behaviour to more normal behaviour */ system ("/bin/stty cooked"); return 0;}
stty cooked
man stty
TA贡献1829条经验 获得超9个赞
'\n'
EOF
#include<stdio.h>#include <termios.h> //termios, TCSANOW, ECHO, ICANON#include <unistd.h> //STDIN_FILENOint main(void){ int c; static struct termios oldt, newt; /*tcgetattr gets the parameters of the current terminal STDIN_FILENO will tell tcgetattr that it should write the settings of stdin to oldt*/ tcgetattr( STDIN_FILENO, &oldt); /*now the settings will be copied*/ newt = oldt; /*ICANON normally takes care that one line at a time will be processed that means it will return if it sees a "\n" or an EOF or an EOL*/ newt.c_lflag &= ~(ICANON); /*Those new settings will be set to STDIN TCSANOW tells tcsetattr to change attributes immediately. */ tcsetattr( STDIN_FILENO, TCSANOW, &newt); /*This is your part: I choose 'e' to end input. Notice that EOF is also turned off in the non-canonical mode*/ while((c=getchar())!= 'e') putchar(c); /*restore the old settings*/ tcsetattr( STDIN_FILENO, TCSANOW, &oldt); return 0;}
putchar()
newt.c_lflag &= ~(ICANON | ECHO);
TA贡献1982条经验 获得超2个赞
- 3 回答
- 0 关注
- 1358 浏览
添加回答
举报