Topics requirements:
write a program, you can always receive keyboard character,
if the character is lowercase uppercase characters corresponding to the output,
if the reception is uppercase, lowercase characters corresponding to the output,
if it is not a digital output.
Ideas:
In this procedure, with ** getchar () and putchar () ** character input and an output; character case conversion is mainly based on the ASCII code table, A to Z in the ASCII code table by 65-90 represents, a to z in the ASCII code table represented by 97 to 122, corresponding to the ASCII value of the difference between the case 32, when performing case conversion, as long as corresponding to plus or minus 32 to complete the conversion, when experiencing digital output directly blank space.
Note:
In the cycling conditions while the character getchar () first input is assigned to ch, then the loop condition is determined
when the input Ctrl z time out while loop
is determined case letters is to be noted between the use condition is determined && connecting
ASCII code table of values corresponding to each letter
Source:
#include<stdio.h>
#include<Windows.h>
void main()
{
char ch;
printf("请输入(若要退出循环则输入Ctrl z):\n");
while ((ch = getchar()) != EOF){
if (ch >= 'a' && ch <= 'z'){
ch -= 32;
putchar(ch);
}
else if (ch >= 'A' && ch <= 'Z'){
ch += 32;
putchar(ch);
}
else{
printf(" ");
}
}
system("pause");
}
operation result: