判断一段字符串中有多少单词(以空格为标准)
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; }
相关文章推荐
- 统计一段字符串中有多少个字母,数字,标点,空格
- Java 写一个方法判断一个字符串是否对称 "asdfgasdfg"、编写一个程序,将下面的一段文本中的各个单词的字母顺序翻转,
- 输入一行字符串,统计其中有多少个单词,单词之间用一个或者多个空格分隔开
- 如何判断一段字符串最后一个单词及其长度?
- 不使用for完成一段有空格间隔的字符串,分辨长度大于等于4的单词(求各位高人修改,我表示我是菜鸟,这个算法实在太长了)
- 输入一段字符,统计其中有多少单词,单词间用空格分开。
- 试编写一个程序,输入一个字符串,统计其中有多少各单词?单词之间用空格分开
- python 中输入一个字符串,判断这个字符串中有多少个字符、数字、空格、特殊字符
- 输入一行字符串(单词和若干空格), 输出该行单词个数 这里用到判断字符与否的isalpha
- 获取一段字符串中每个单词的次数(用空格分隔)
- 编写一段程序,从标准输入中读取多个字串并将他么连接起来,输出成大的字符串。 改写上述程序,用空格把输入的多个字符串分割开来。
- 去掉一段字符串中的空格,以#结束-C语言经典代码-编程
- 判断字符串中是否有空格
- 计算字符串中的单词数(单词:由空格分开的连续字母数字串)
- java实现 计算字符串最后一个单词的长度,单词以空格隔开。
- 编程在一个已知的字符串中查找最长单词,假定字符串中只含字母和空格,用空格来分隔单词(只使用循环,数组)
- 判断是否为素数和统计字符串中单词的个数
- java里一段字符串按照空格拆分,然后再按逗号拆分怎么写
- js判断字符串 空 null 空格
- 写一个程序,用于分析一个字符串中各个单词出现的频率,并将单词和它出现的频率输出显示。(单词之间用空格隔开,如“Hello World My First Unit Test”)