您的位置:首页 > 其它

C实例---键盘输入字符串,统计空格

2017-01-04 17:41 197 查看
代码:

#include <stdio.h>

int Num(const char *s)
{
int count = 0;
while (*s != '\0')
if (*s ++ == ' ')
count ++;

return count;
}

int main ()
{
char s[200];

scanf("%[^\n]",s);
//gets(s); //有警告
printf("%d\n", Num(s));
return 0;
}


运行效果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  字符串-空格
相关文章推荐