1. read one character from the buffer, equivalent to clear buffer
2. The previous scanf () will leave a character ' \ n ' (after entering the value of s[i] in the buffer when reading the input, so if you do not add a getchar () to take this carriage return, get () will not wait to type the character from the keyboard, Instead, it takes the "useless" carriage return directly, causing the read to be incorrect.
3. GetChar () is a character read in the input buffer order (including spaces, carriage return and TAB) GetChar () is inconvenient to use, Workaround: (1) Use the following statement to clear the carriage return: while (GetChar ()! = ' \ n '); (2) Replace GetChar () with Getche () or Getch (), which is used to read a character from the keyboard (do not press ENTER), note to include the header file <conio.h>
4. "Turn" GetChar () is a library function in the stdio.h, its role is to read a character from the stdin stream, that is, if the stdin has data, it can be read without input, the first time GetChar (), it does require manual input, But if you lose more than one character, the subsequent getchar () will be read directly from the buffer when it is executed. In fact, the input device--memory buffer---Program getchar you press the key is put into the buffer, and then for the program GetChar you have not tried to hold a lot of keys and then wait a moment will drip drops, that is, the buffer is full, you press the key is not stored in the buffer. Keyboard input characters are stored in the buffer, once you type Enter, GetChar into the buffer to read the characters, only return the first character as the value of the GetChar function at a time, if there is a loop or enough GetChar statement, it will read out all the characters in the buffer until ' \ n '. To understand this, the sequence of characters you enter is read sequentially because the function of the loop is to reuse GetChar to read the characters in the buffer, instead of GetChar to read multiple characters, in fact GetChar can only read one character at a time. If you need to cancel the ' \ n ' effect , can be used GetChar (), to clear, here GetChar (); just got ' \ n ' but not assigned to any character variable, so there's no effect, This is the equivalent of erasing this character. Also note that here you enter SSSS on the keyboard to see the echo is from the role of GetChar, if you use getch can not see what you entered.
GetChar () Usage "Go"