云天明的童话:大家看看这题怎么编程啊?

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/05 19:01:47
由键盘任意输入一串字符,将其中的大写字母改写为小写字母,而所有小写字母改写为大写字母,其他字符不变,要求分行输出改变后的两个字符串.

#include <ctype.h> //字符操作函数库
main()
{
char str[81]; //最大可输入80长度的字符串
int i=0;
scanf("%s",str);
printf("The old string is: %s\n",str);
while(str[i])
{
if (isupper(str[i]))
{
str[i]=tolower(str[i]);
}
else
{
if (islower(str[i]))
str[i]=toupper(str[i]);
}
i++;
}
printf("The new string is: %s\n",str);
return 0;
}

c=getchar();

{
if {c>=A$$c<=Z;
c=c+32;}
else c=c-32;

}
其余的自己补充

#include <stdio.h>
char uper[20],lower[20];

void function()
{
int i,j;
printf("请输入字符串:\n");
gets(uper);
i=strlen(uper);
for(j=0;j<i;j++)
if(uper[j]>='a'&&uper[j]<='z')
lower[j]=uper[j]-32;
else if(uper[j]>='A'&&uper[j]<='Z')
lower[j]=uper[j]+32;
else
lower[j]=uper[j];

}
int main()
{
function();
printf("改变前:");
puts(uper);
printf("改变后:");
puts(lower);
return 0;
}