#include<stdio.h> int main() { int one; int two; printf("please enter one char:\n"); one = getchar(); two = one - 32; putchar(two); printf("%c\n",two); putchar('\n'); return 0; }
小写字母的ascii码值比大写字母大32;
但是我这台电脑的ascii码查出来只有1~127,开始时错把减号写成加号,导致输出的结果是该数的八进制(输入a,输出201这是八进制的129)
#include<stdio.h> int main() { int one; int two = 0; printf("please enter one char:\n"); one = getchar(); while(one != EOF) { if(one >='a'&& one <= 'z') two = one - 32; putchar(two); one = getchar(); } return 0; }
这个更优化哩!可以输出一整串,上面那个只可以输入一个