Converts uppercase and lowercase letters to uppercase and lowercase letters.
// Kailu garji-blog Park Co., http://www.cnblogs.com/kailugaji/.
Method 1:
1 # include <stdio. h>
2 # include <stdlib. h>
3 // 32-bit
4 void main () {
5 char ch, t;
6 printf ("Please input a letter: \ n ");
7 ch = getchar ();
8 t = getchar (); // absorb the Enter key
9
10 while (ch <'A' & ch> 'Z ') | (ch <'Z' & ch> 'A') {
11 printf ("Input error! \ NPlease input again: \ n ");
12 ch = getchar ();
13}
14
15 if (ch & 32)
16 ch = ch & 223; // change the fifth digit to 0 and the fifth digit to
17 else ch = ch | 32; // reduce the fifth digit to 1 and write
18
19 putchar (ch );
20 printf ("\ n");
21}
Method 2:
1 # include <stdio. h>
2 # include <stdlib. h>
3 // 32-bit
4 void main () {
5 char ch;
6 printf ("Please input a letter: \ n ");
7 scanf ("% c", & ch);
8 ch = (ch> = 'A' & ch <= 'Z ')? (Ch + 32) :( (ch> = 'A' & ch <= 'Z ')? (Ch-32): printf ("Input error! ");
9 printf (" % c \ n ", ch);
10}
Result: