更改大小写

81 阅读1分钟

Description
将输入一行字符串(小于80个字符),将其中的所有小写字母改为大写,其他字符不变。
Input
输入一行字符串,以回车结束。
Output
将字符串中小写字母改大写后输出。
Sample Input
There are 3 pens.
Sample Output
THERE ARE 3 PENS.

#include<stdio.h>
int main()
{
	int i=0;//对a[]是从a[0]开始的,所以先设i=0
	char a[80];
	gets(a);//gets() 函数将接收输入的整个字符串直到回车为止。 
    while(a[i]!='\0')//这是字符串结束的标志。 
    {
    	if(a[i]>='a'&&a[i]<='z')
    	a[i]=a[i]-'a'+'A';//ascll码值来说要-32
    	i++; 从079
	}
	printf("%s",a);//%s用于数组中,这里输出数组所有值,,不是单个输出
	return 0;
	
}