| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2273 人关注过本帖
标题:C PRIMER PLUS(第五版)第178页7.7.2
取消只看楼主 加入收藏
kuaisha
Rank: 2
等 级:论坛游民
帖 子:120
专家分:30
注 册:2016-8-3
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:3 
C PRIMER PLUS(第五版)第178页7.7.2
程序代码:
#include<stdio.h>
#include<ctype.h>
int main(void)
{
    char ch;
    printf("Give me  letter of the alphaber,and Iwill give");
    printf("an animal name\nbeginning with that letter.\n");
    printf("Please type in a ltter;type # to end my act.\n");
    while((ch = getchar())!= '#')
    {
        if('\n' == ch)
           continue;
        if(islower(ch))
           switch(ch)
        {
            case 'a':
                printf("argali,a wild sheep of Asia\n");
                break;
            case 'b':
                printf("babirusa,a wild pig of malay\n");
                break;
            case 'c':
                printf("coati, racoonlike mammal\n");
                break;
            case 'd':
                printf("deman, aquatic,moleoike critter\n");
                break;
            case'e':
                printf("echidna,the spiny anteater\n");
                break;
            case 'f':
                printf("fisher,brownish marten\n");
                break;
            default:
                printf("That's a stumper!\n"); 
        }
        else
            printf("I recognize only lowecase letters.\n");
        while(getchar()!='\n')
            continue;
        printf("Please tyoe another leter or a #.\n");
    }
    printf("Bye!\n");
    return 0;

while(getchar()!='\n')
            continue;
这行我知道是跳过输入行剩余的部分,但我不理解。
搜索更多相关主题的帖子: PRIMER printf continue case break 
2017-08-12 16:14
kuaisha
Rank: 2
等 级:论坛游民
帖 子:120
专家分:30
注 册:2016-8-3
收藏
得分:0 
回复 2楼 marlow
我调试了一下,为什么当我输入ded的时候,它经过了case‘d’然后就直接跳到了contiue;,为什么它是跳到这行,而不是while(getchar()!='\n').break不是跳过下一跳语句吗,那应该跳过else而不是while?
2017-08-12 20:27
kuaisha
Rank: 2
等 级:论坛游民
帖 子:120
专家分:30
注 册:2016-8-3
收藏
得分:0 
回复 4楼 marlow
我还是不太懂,因为执行了if(islower(ch))所以就不执行else了,又因为break是跳过switch的,所以他不应该到下一条while(getch()!=‘\n’)指令吗,为什么到continue?
2017-08-12 22:05
kuaisha
Rank: 2
等 级:论坛游民
帖 子:120
专家分:30
注 册:2016-8-3
收藏
得分:0 
回复 6楼 marlow
2017-08-13 17:11
快速回复:C PRIMER PLUS(第五版)第178页7.7.2
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.153520 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved