#include<stdio.h>
int countw(char *str)
{
char c;
int i=0,num=0,word=0;
while((c=str[i])!='\0'){
if(c==' '||c==','||c=='.'){
word=0;
}
else if(word==0){
word=1;
num++;
}
i++;
}
return num;
}
main()
{char s[200];
gets(s);
printf("There are %d words.\n",countw(s));
}
编写函数int countw(char *str),统计字符串str中单词的个数。单词之间以空格,逗号,句号作分隔,数字也看做单词。单词之间可能不止一个分隔符。如输入: It‘s 10:10
最新推荐文章于 2023-04-06 15:34:44 发布