标题:getchar()有清除缓冲区的功能?
取消只看楼主
michaelyj
Rank: 1
来 自:上海
等 级:新手上路
帖 子:55
专家分:0
注 册:2009-10-27
结帖率:88.24%
已结贴  问题点数:20 回复次数:0 
getchar()有清除缓冲区的功能?
#include <stdio.h>
#include <ctype.h>

int main(void)
{
    char ch;
    printf("please type in a letter: type # to end my act.\n");
    while((ch = getchar()) != '#')
    {
        if('\n' == ch)
            continue;
        if(islower(ch))
            switch(ch)
            {
                case 'a':
                    printf("argali\n");
                    break;
                case 'b':
                    printf("babirusa\n");
                    break;
                case 'c':
                    printf("coati\n");
                    break;
                case 'd':
                    printf("desman\n");
                    break;
                case 'e':
                    printf("echidna\n");
                    break;
                case 'f':
                    printf("fisher\n");
                    break;
                default:
                    printf("That's a stumper!\n");
            }
        else
            printf("I recognize only lowercase letters.\n");
        while(getchar() != '\n')
            continue;
        printf("Please type another letter or a #.\n");
    }
    printf("Bye!\n");
    getchar();
    getchar();
    return 0;
}

上面这个循环是不是就起到了这样的功能?
搜索更多相关主题的帖子: 缓冲区 getchar 
2010-03-16 11:27



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




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

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