鱼C论坛

 找回密码
 立即注册
查看: 3894|回复: 0

求助:C Primer Plus第8章练习4,看不明

[复制链接]
发表于 2013-6-8 21:00:49 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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;        /*到达单词的尾部*/
看得不是好明白,求讲解
初学的,求助,谢谢

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-24 11:52

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表