#include <stdio.h>
#include <string.h>
#define SIZE 100
int main()
{
char str[SIZE] = { '\0' };
int count = 0;
printf("please input the string\n");
gets(str);
puts(str);
int length = strlen(str);//字符串的长度
for (int i = 0; i < length; i++)
{
//判断是不是空格 不是的话在while里面i++执行判断到下一个空格的出现或是结束
if (str[i] != ' ')
{
count++;
while (str[i] != ' ' && str[i] != '\0')
{
i++;
}
}
}
printf("%d\n", count);
return 0;
}
统计字符串中单词的个数
猜你喜欢
转载自blog.csdn.net/weixin_43831728/article/details/97402928
今日推荐
周排行