zoukankan      html  css  js  c++  java
  • 有关continue的小程序(1)

    看一个 continue的程序

    c prim plus 7.9

     1 #include<stdio.h>
     2 #include<ctype.h>
     3 int main(void)
     4 {    char ch;
     5     printf("        You give me a letter,
            and I give you a word;
    "
     6            "        Input  a # to quit
    ");
     7     while((ch=getchar())!='#')
     8     {
     9         if('
    ' == ch) continue; //处理刚开始输入的换行符 
    10         
    11         if(islower(ch))
    12             switch(ch)
    13             {
    14                 case 'a': printf("apple
    "); break;
    15                 case 'b': printf("basketball
    "); break;
    16                 case 'c': printf("cell
    "); break;
    17                 case 'd': printf("desirable
    "); break;
    18                 case 'e': printf("elements
    "); break;
    19                 case 'f' :printf("fisher, brownish marten
    ");break;
    20                 default: printf("this is a beautiful world!
    "); break;
    21             }
    22         else
    23             printf("Input a lowercase letter.
    ");
    24     
    25     /*读取并丢弃输入,直至一行的末尾*/
    26     while( getchar()!='
    ') continue; //跳过输入行的剩余部分 
    27         
    28         printf("Input another letter
    ");
    29         printf("----------------------
    ");        
    30             
    31     }
    32     printf("Bye····
    "); 
    33     return 0;
    34 }

    实验结果如下:

    范的错误,我第9行 

    if('
    ' == ch) continue;   刚开始写为了 if('
    ' == getchar()) continue; 这样呢,比如输入 两个字符,才能进入switch···呜呜呜····以后注意哦···
  • 相关阅读:
    J2EE(一)——开发简单WEB服务器
    日报--2015年7月10日
    MVC @Html控件(转载)
    Asp.NET MVC--【Asp.net】
    附加到进程 调试技巧--【VS】
    快速阅读学习方法笔记
    匿名函数和闭包--【JavaScript】
    Repeater显示数据--[Asp.Net]
    FileUpLoad上传文件--[Asp.Net]
    35Canlender--[Asp.Net]
  • 原文地址:https://www.cnblogs.com/kalo1111/p/3277805.html
Copyright © 2011-2022 走看看