| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 522 人关注过本帖
标题:高手帮我看看这个问题!
只看楼主 加入收藏
devfhpgah
Rank: 1
来 自:江西
等 级:新手上路
帖 子:204
专家分:0
注 册:2007-8-16
收藏
 问题点数:0 回复次数:1 
高手帮我看看这个问题!
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
int main(void)
{
    char ch;
    for(;;)
    {
        puts("按a)");
        puts("按b)");
        puts("按q)");
        printf("Input:");
        switch(tolower(ch=getchar()))
        {
          while(getchar()!='\n')
           continue;         
          case 'a':
           printf("\nThis is %c\n",ch);
           break;
          case 'b':
           printf("\nThis is %c\n",ch);
           break;
          case 'q':
           exit(EXIT_FAILURE);
          default:
           printf("\nError.\n");
        }
    }
        
    return 0;
}

问题:为什么红色部while(getchar()!='\n') 这条两 语句没有吃掉'\n'!
                   continue;
搜索更多相关主题的帖子: cas continue include 
2008-03-15 16:09
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
收藏
得分:0 
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
int main(void)
{
    char ch;
    for(;;)
    {
        puts("按a)");
        puts("按b)");
        puts("按q)");
        printf("Input:");
        switch(tolower(ch=getchar()))
        {
          while(getchar()!='\n')
           continue;         
          case 'a':
           printf("\nThis is %c\n",ch);
           break;
          case 'b':
           printf("\nThis is %c\n",ch);
           break;
          case 'q':
           exit(EXIT_FAILURE);
          default:
           printf("\nError.\n");
           
        }
        fflush(stdin);
    }
}论坛登不上啊..希望可以坐到沙发..

学习需要安静。。海盗要重新来过。。
2008-03-15 16:17
快速回复:高手帮我看看这个问题!
数据加载中...
 
   



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

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