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 關注
- 1384 瀏覽
添加回答
舉報