Let's start with a simple practice procedure:
1#include <stdio.h>2 3 intMain ()4 {5 intC, n =0 ;6 while((c = GetChar ())! ='Q' )7printf"Char%3d is%ccode%d\n", n++, C, c);8 return 0 ;9}
This is the program after the compilation of the effect of running, you can see after entering hello after hitting enter to run the program, that is, the characters entered in the terminal is actually buffered.
In addition, the ENTER key itself is recognized as a newline, and is also recognized by the program, which is also related to the terminal settings.
The TTY driver contains many operations on the data:
- Input: How the driver handles characters from the terminal
- Output: How the driver handles characters flowing to the terminal
- Control: How characters are represented--the number of bits, the parity of bits, the stop bit, etc.
- Local: How the driver handles characters from inside the driver
Writing terminal drivers: about system call functions:
Understanding unix/linux Programming-stty Instruction Exercise