标题:程序有几个部分看不懂,望指点!
取消只看楼主
木子李
Rank: 1
等 级:新手上路
帖 子:4
专家分:2
注 册:2014-2-27
结帖率:100%
已结贴  问题点数:20 回复次数:1 
程序有几个部分看不懂,望指点!
void scan_fraction(int *nump,int *denomp)
{
    char slash;
    int status;
    int error;
    char discard;
    do {
        error=0;
        printf("Enter a common fraction as two integers separated");
        printf("by a slash\n");
        status=scanf("%d %c%d",nump,&slash,denomp);
        if (status<3){
            error=1;
            printf("Invalid-please read directions carefully\n");
        }else if (slash!='/'){
            error=1;
            printf("Invalid-separate numerator and denominator");
            printf("by a slash(/)\n");
        } else if (*denomp<=0){
            error=1;
            printf("Invalid-denominator must be positive\n");
        }
        do{
            scanf("%c",&discard);
        }while (discard!='\n');
    }while (error);
}

这是一个子函数,为了得到一个分数。
第十二行的  status<3  不能理解其具体的作用;
还有这个循环   
             do{
            scanf("%c",&discard);
        }while (discard!='\n');
不知道是干嘛的,望各位大侠指点。拜谢!
搜索更多相关主题的帖子: carefully common status Enter 
2014-02-27 10:21
木子李
Rank: 1
等 级:新手上路
帖 子:4
专家分:2
注 册:2014-2-27
得分:0 
回复 2楼 so_love
非常感谢,后面那个循环我还是不太懂,为什么要判定输入的是'\n'?  具体起到什么作用? 麻烦大神了。
2014-02-28 09:24



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-427737-1-1.html




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

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