c语言题目:从键盘输入一个字符串存入数组s[80],统计该字符串的长度并将其中所有小写字母改为大写字母……

然后再将将结果输出。

#include<stdio.h>
#include<string.h>
int main()
{
char s[80];
int len,i;
gets(s); //输入一段字符
len=strlen(s); //计算字符串长度
for(i=0;i<len;i++)
{
if(s[i]>='a'&&s[i]<='z') //将小写字母转换为大写
s[i]=s[i]-32;
}
printf("%d\n",len); //输出字符串长度
puts(s); //输出修改后的字符串
return 0;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-04-12
高手版:
#include <stdio.h>
#include <string.h>
void main(void)
{
char s[80];
gets(s);
strupr(s);
int len=strlen(s);
printf("%d\n%s\n",len,s);
}
新手版:
#include <stdio.h>
void main(void)
{
char s[80];
for(int i=0;(s[i]=getchar())!='\n';i++)
{
if(s[i]>='a'&&s[i]<='z')
s[i]=s[i]-32;
}
s[i]='\0';
printf("%d\n%s\n",i,s);
}本回答被网友采纳
第2个回答  2012-05-16
/*
输入字符串 : asdZXC123<>[]
字符串的长度为 : 13
转换后为 : ASDZXC123<>[]
请按任意键继续. . .
*/
#include <stdio.h>

int strlen(char *s) { // 计算字符串s的长度
int len = 0;
while(s[len])len++;
return len;
}
char *atou(char *s) { // 将小写字母转换为大写,其他不变
int i;
for(i = 0; s[i]; ++i) {
if((s[i] >= 'a') && (s[i] <= 'z'))
s[i] = s[i] - 'a' + 'A';
}
return s;
}

int main() {
char s[81];
printf("输入字符串 : ");
gets(s);
printf("字符串的长度为 : %d\n",strlen(s));
printf("转换后为 : %s\n",atou(s));
return 0;
}
相似回答