高仿模拟练习,补全 found 标记处空缺,答案点击按钮展开
fun函数统计字符串中大写字母的数量,请补全found处空缺。
#include <stdio.h>
int fun(char *s)
{
int cnt=0;
while(*s!='\0')
{
/**********found**********/
if(*s>='A' && ___1___ )
/**********found**********/
___2___;
/**********found**********/
___3___;
}
return cnt;
}
int main()
{
char str[100];
gets(str);
printf("upper=%d\n",fun(str));
return 0;
}
*s<='Z'
cnt++
s++
第1空判断当前字符是否为大写字母;第2空计数器加1;第3空指针移动到下一个字符。测试输入:HelloWorld,输出upper=2。