您的位置:首页 > 其它

字符串转换,将其中的大写字母变小写字母,小写字母变大写字母,并输出 。

2013-10-20 17:16 423 查看
从键盘输入一个字符串,将其中的大写字母变小写字母,小写字母变大写字母,并输出 。

【要求】

  (1)用字符数组表示存储字符串(字符串最大为100)。

  (2)使用scanf函数逐个输入字符保存在字符数组中

  (3)使用printf函数逐个输出字符数组中的字符

//输入会自动判断。

#include<stdio.h>
void main()
{
int i=0;
char a[100],c;

printf("Please input char:\t");
do{
scanf("%c",&a[i]);
c=a[i];
i++;
}while(c!='\n');

a[i]='\0';

i=0;
printf("Output char:\t");
while(a[i]!='\0')
{
printf("%c",a[i]);
i++;
}
printf("Result:\t");
i=0;
while(a[i]!='\0')
{
c=a[i];
if(c>='a' && c<='z')
a[i]-=32;
else if(c>='A' && c<='Z')
a[i]+=32;
printf("%c",a[i]);
i++;
}
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐