2_25 Summary of Brush Questions

'Micro manipulation' of scanf function

Obviously, the application of the ASCII code value under investigation
Read the question carefully, the title describes "multiple input", we can use the while loop to achieve!
Through reference, the ASCII code value +32 of uppercase letters is the corresponding lowercase letter.
Look at the code:
Knocked out the code we analyzed!
However, when testing next, the value is not what we expected.

Here is an extra *, so I went to carefully check the usage of scanf, and we typed'A' and hit Enter, the buffer really appeared'A\n', and the scanf function recorded'A' this time Yes, the next time you record'\n', and the ASCII code value of'\n' +32 is *!
At this point, the problem is found, but how to solve it.
When we enter the loop, we can use getchar() to enter.
Look at the effect:
Corrected

The answer is what we want!

Same type of questions

Insert picture description here
This is to determine whether the input is a letter. After having the foundation just now, go directly to the original code and add additional if judgments.
Insert picture description here
Of course, there is another comparison method.
Insert picture description here

study well!

You must remember the usage of some basic functions, including the return type and variable type. You can't just know the general idea!

Guess you like

Origin blog.csdn.net/m0_52751535/article/details/114099218