a program a day 10
2010-10-06 09:19
183 查看
/**
统计字符串中包含单词的个数
**/
#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;
}
统计字符串中包含单词的个数
**/
#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;
}
相关文章推荐
- hackerrank Day 10: Binary Numbers
- day_1_10 JavaWeb系列学习总结之servlet
- the Secret DAILY TEACHINGS-Day 10
- Day 10: PhoneGap —— 开发手机应用如此简单
- [题解]CLYZ2018省选训(bao)练(zha)模拟赛 Day 10
- Day-10 选择排序
- 开发日志 10-day
- [置顶] 唐宇迪博士视频课学习day_10
- day 10 find命令
- Swift 2.0学习笔记(Day 10)——运算符是“ +、-、*、/ ”吗?
- JZOJ__Day 10:【普及模拟】【USACO】横幅
- (30 hackdays day 10) Material design - 可用的Material
- 10 Things Extraordinary People Say Every Day
- Day 10
- One-day-one-program(3)之统计字符串中不同字母的个数
- 黑马程序员--StringBuffer类数组高级Arrays类包装类day(10)
- 【day-10】寻找前K大个数-快排
- python-day-10-python mysql and ORM
- day 10......oh time fries .....
- DAY-10作业