|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
网上源码是这样的:
#include<stdio.h>
#include<ctype.h>
int main(void)
{
char ch;
int words = 0;
int n_words = 0;
bool inwords = false;
while((ch = getchar()) != EOF)
{
if(!ispunct(ch) && (!isspace(ch)))
words++;
if(!isspace(ch) && !inwords)
{
inwords = true; /*开始一个新单词*/
n_words++; /*统计单词数*/
}
if(isspace(ch) && inwords)
inwords = false; /*到达单词的尾部*/
}
printf("%d characters read.\n",words);
printf("%d words read.\n",n_words);
printf("The average number of letters per word is %f.\n",
(float)words/(float)n_words);
return 0;
}
但在
if(!isspace(ch) && !inwords)
{
inwords = true; /*开始一个新单词*/
n_words++; /*统计单词数*/
}
if(isspace(ch) && inwords)
inwords = false; /*到达单词的尾部*/
看得不是好明白,求讲解
初学的,求助,谢谢
|
|