改正C小程序

来源:百度知道 编辑:UC知道 时间:2024/05/22 14:03:35
编写程序,从键盘输入一个字符串,调用count()函数统计大写字母的个数。
#include "stdio.h"
/*统计函数count()的说明*/int count(char str[ ]);

void main( )
{ char s[80];
/*提示请输入一串字符*/printf("请输入一串字符");
/*用scanf()函数输入一个字符串*/scanf("%s",&s[]);
printf("该字符串中大写字母的个数为:%d\n",count(s));
}
int count(char str[ ])
{ int i=0,c=0;
/* while 循环*/while(i)
/*if条件判断某字符是否是大写字母*/if (c=)
/*符合条件,进行累加*/i++;
/*返回统计结果*/return(count);
}
#include "stdio.h"
/*统计函数count()的说明*/int count(char str[ ]);

void main( )
{ char s[80];
/*提示请输入一串字符*/printf("请输入一串字符");
/*用scanf()函数输入一个字符串*/scanf("%s",&s[]);
printf("该字符串中大写字母的个数为:%d\n",count(s));
}
int count(char str[ ])
{ int i=0,c=0;
/* while 循环*/while(

#include <stdio.h>
int count(char str[ ]);
int main( )
{
char s[100];
printf("请输入一串字符");
scanf("%s",s);
printf("该字符串中大写字母的个数为:%d\n",count(s));
return 0;
}

int count(char str[ ])
{
int i=0,c=0;
char ch;
while((ch=str[i])!='\0')
{
if ('A'<=ch && ch<='Z')
c++;
i++;
}

return c;
}

应该这样改:
void main( )
{ char s[80]; int cc;
printf("请输入一串字符"); /*提示请输入一串字符*/
scanf("%s",&s); /*用scanf()函数输入一个字符串*/
cc=count(s);
printf("该字符串中大写字母的个数为:%d\n",cc);
}
int count(char str[ ])
{ int i=0,c=0;
while(i++&&str[i]!='\0') /* while 循环*/
{
if (str[i]>='A'&&str[i]<='Z') /*if条件判断某字符是否是大写字母*/
c++; /*符合条件,进行累加*/
}
return(c); /*返回统计结果*/