这个程序怎么写:从键盘输入一个字符串,将其中的小写字母改为大写字母,其他字符不变,并输出这个字符串

这个程序怎么写:从键盘输入一个字符串,将其中的小写字母改为大写字母,其他字符不变,并输出这个字符串,分析运行结果,用字符数组处理。

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

printf("请输入字符串的内容:\t");
do{
scanf("%c",&a[i]);
c=a[i];
i++;
}while(c!='\n');

a[i]='\0';

i=0;
printf("输入字符串的内容为:\t");
while(a[i]!='\0')
{
printf("%c",a[i]);
i++;
}
printf("转换后字符串的内容为:\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++;
}
}追问

题目一开始没有给数组长度是100啊

温馨提示:内容为网友见解,仅供参考
第1个回答  2015-06-12
#include <stdio.h>

void change(char s[])
{
int i;
for(i=1;i<=20;i++)
{
if(s[i]>='a'&&s[i]<='z')
s[i]=s[i]-32;
}
}

main()
{

char str[100]="";
scanf("%s",str);

clrscr();
change(str);
printf("%s\n",str);
}
相似回答