文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>a program a day 10

a program a day 10

时间:2010-10-06  来源:生无涯

/**
统计字符串中包含单词的个数
**/
#define MaxSize 100
#include<stdio.h>
int cWords(char * str)
{
 int count = 0,flag = 5;  //the initial value of flag should be larger than 2
 char * p = str;
 while(*p != '\0')
 {
  if(*p >= 'A' && *p <= 'Z'||*p >= 'a' && * p <= 'z')
   flag =1;
  else
   flag++;
  if(flag == 2)
   count++;
  p++;
 }
 if(flag == 1)          //the string doesn't ends with punctuation(标点)
  count++;
 return count;
}
int main()
{
 char str[] = "you are welcome!";
 printf("%s",str);
 printf("\n%d\n",cWords(str));

 char str1[] = "jia yu sheng"; //the string doesn't ends with punctuation(标点)
 printf("%s",str1);
 printf("\n%d\n",cWords(str1));

 char str2[] = "    you...are..welcome!";
 printf("%s",str2);
 printf("\n%d\n",cWords(str2));

 char str3[] = " ";
 printf("%s",str3);
 printf("\n%d\n",cWords(str3));
 return 1;
}

相关阅读 更多 +
排行榜 更多 +
野生恐龙射击生存安卓版

野生恐龙射击生存安卓版

飞行射击 下载
战场狙击手

战场狙击手

飞行射击 下载
1v1布娃娃射击安卓版

1v1布娃娃射击安卓版

飞行射击 下载