read changes stdout from unbuffered to line buffered in canonical mode
问题 When I use this piece of code in canonical mode: #include <stdio.h> #include <termios.h> #include <unistd.h> static struct termios newt; static struct termios oldt; static void kb_fini(void) { tcsetattr(STDIN_FILENO, TCSANOW, &oldt); } void kb_init(void) { tcgetattr(STDIN_FILENO, &oldt); newt = oldt; newt.c_lflag &= (tcflag_t)~(ICANON | ECHO | ISIG); newt.c_cc[VMIN] = 1; newt.c_cc[VTIME] = 0; tcsetattr(STDIN_FILENO, TCSANOW, &newt); atexit(kb_fini); } int main(void) { int c; kb_init(); printf