<> cause :

A question on niuke.com , Multiple groups of letters per line are required , Then output the converted case letters by line , Let's talk about it .

<> analysis :

There are two important points to note , One is to input multiple groups by line , The second is to convert letters into upper and lower case . First, multi group input by line , We can use while Cycle through multiple sets of inputs ,scanf() perhaps getchar() Function to get the input value ; Then the case conversion of letters needs to be based on ASCLL Table to analyze , We can see in the table that the decimal system of upper and lower case letters is actually a difference 32 of , Therefore, you only need to make the input letters decimal ±32 Operation to achieve conversion .

Here you may have questions , Letters belong to char type ,32 yes int type , Does this work ?

The answer is yes . When calculating ,char Type can be converted to int Type ( Customized conversion during calculation , No cast required ). The computer finds the ASCII value ( decimal system ), Use it in ASCII Add and subtract the corresponding value in , Of course two char Type operations also require such conversions .

<> Solution :

After explaining the principle, we can implement it in code

Method 1 : We use scanf() Function receive input , then printf output
int main() { int input = 0; while ((scanf("%c", &input)) != EOF) { /*if (input
= '\n') continue;*/ // If running the program according to enter affects the conversion , You can add this statement , Skip carriage return character '\n' if (input >= 'A'
&& input <= 'Z') { input = input + 32; printf("%c\n", input); } else if (input
>= 'a' && input <= 'z') { input = input - 32; printf("%c\n", input); } } return
0; }
After the program runs

Method II : use getchar() Function get input , use putchar() output Maybe some friends don't understand getchar() function , We can take a look at the library description

In fact, it is simply to get the characters entered by the keyboard one by one , The returned value is ASCLL Code decimal value , Return if reading error EOF,putchar() The principle is similar , Here is the implementation :
int main() { char input = 0; while ((input = getchar()) != EOF) { if (input >=
'A' && input <= 'Z') { input = input + 32; putchar(input); printf("\n"); } else
if (input >= 'a' && input <= 'z') { input = input - 32; putchar(input); printf(
"\n"); } } return 0; }
Running results

©2019-2020 Toolsou All rights reserved,
evo Tool usage problems ——Degenerate covariance rank, Umeyama alignment is not possible Experiment 4 Automated test tools - software test mysql Export data sql sentence _mysql according to sql Query statement export data Create a thread ——— Javaweb (3) Data structure experiment ( three )—— Stacks and queues TS stay vue2 Writing in the project web Front end signature plug-in _signature_pad Plug in implements electronic signature function docker Where is the image stored Qt Getting Started tutorial 【 Basic controls 】QCalendarWidget calendar control springboot How to get reality in ip address