#include<stdio.h>
#define N 100
int main()
{
char s[N];
int i;
int count=0;//计数
int a=0;//判断是否计数的标志
printf("Please Enter s:\n");
gets(s);
for(i=0;s[i];i++)
{
if(s[i]==' ')
a=0;
else
if(a==0)
{
a=1;
count++;
}
}
printf("单词数:%d\n",count);
return 0;
}
计算字符串中的单词数. 单词:由空格分开的连续字母数字串。
最新推荐文章于 2022-09-30 15:56:20 发布