您的位置:首页 > 其它

判断一段字符串中有多少单词(以空格为标准)

2009-10-23 18:37 253 查看
直接上代码

#include <stdio.h>
#include <string.h>

int wordscount(const char *s)
{
char *p = (char*)s;
int count = 0;

while (*p != '/0')
{
/*去掉空格*/
while (*p == ' ')
{
++p;
}
/*单词计数*/
if (*p != '/0')
{
++count;
}
/*跳去单词*/
while (*p != ' ' && *p != '/0')
{
++p;
}
}

return count;
}

int main()
{
char s[100];
printf("please input the strings:/n");
gets(s);
printf("%d/n",wordscount(s));

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