#include <stdio.h>

 /*
给出一字符串指针,计算出字符串指针中单词数,
单词不包括'.',',',';','?','_','"',由0-9数字或26个字母组成
by zww @ 2013.09.26
vc 6.0编译通过
*/ unsigned int get_string_word_cnt(const char* pStr)
{
unsigned int iCnt= ;
unsigned int iCharCnt = ;
const char* p = pStr; if (NULL == pStr)
{
return ;
} while ('\0' != *p)
{
if (('.' == *p)
|| (',' == *p)
|| (';' == *p)
|| ('?' == *p)
|| (' ' == *p)
|| ('_' == *p)
|| ('"' == *p))
{
printf("[%c]",*p);
iCharCnt=;
}
else if (!((*p >= 'a'&& *p<='z')
|| (*p >='A' && *p<='Z')
|| (*p >= '' && *p <='')))
{
printf("[%c]",*p);
iCharCnt = ;
}
else if ( == iCharCnt)
{
iCharCnt++;
iCnt++;
} p++;
} return iCnt;
} int main()
{
char * str1 = "hello world.1...2";
char * str2 = "hello world.sd,fg!@!$!$!!!!!!!!!!!!hj.";
char * str3 = "hello world.fdfg)(*&&&*(hjdfh?>><>,...";
char * str4 = ".hello world.12";
int i = ;
i = get_string_word_cnt(str1);
printf(" %d\r\n",i);
i = get_string_word_cnt(str2);
printf(" %d\r\n",i);
i = get_string_word_cnt(str3);
printf(" %d\r\n",i);
i = get_string_word_cnt(str4);
printf(" %d\r\n",i); return ;
} /**
显示结果如下:
[ ][.][.][.][.]4
[ ][.][,][!][@][!][$][!][$][!][!][!][!][!][!][!][!][!][!][!][!][.]5
[ ][.][)][(][*][&][&][&][*][(][?][>][>][<][>][,][.][.][.]4
[.][ ][.]3
Press any key to continue
**/
04-28 01:05