When you run the scanf function, scanf is often skipped. This is because when you have done the scanf function, in the second scanf function, because the buffer is still stored in the first end of the carriage return, the second time did not read into the carriage return directly into the, so there is no real read into the data role. At this point we can clear the buffer, and here we can use the Fflush function. Let's take a look at the Fflush function:
The flow in the graph is the data transmission in the computer (reading and writing, network connection transmission) is abstracted as a stream, the transmission of data is like flowing water, flow from one container to another. The flow is generally divided into 3 types, standard input (stdin), standard output (stdout), and error Output (stderr). After understanding the function and the flow, let's look at an example,
Why is the int type I input 123CV? Because our default user is unfriendly, no one knows what the user will do. As you can see, the "C" of the buffer is directly assigned to the B variable. Here you can think of the second scanf function being skipped, of course scanf is skipped more than this one, to see the result after adding the Fflush function:
Joined the Fflush no problem!
But there is another way to use GetChar (), but GetChar can only skip one character,
As you can see, the character "C" is skipped.
So in the programming time encountered scanf was skipped or with the Fflush function is better.
C-language scanf skipped issues