通过ASCII表查询知道大写字母与小写字母相差32,可以利用这个特性,从而实现大小写字母的转换。
#include<stdio.h>
//a-97 A-65
//b-98 B-66
int main()
{
char arr[] = "I am a Student";
int i = 0;
while (arr[i] != '\0')
{
if (arr[i] >= 'a' && arr[i] <= 'z')
{
arr[i] -= 32;
}
i++;
}
printf("%s", arr);
}