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