zoukankan      html  css  js  c++  java
  • 枚举练习

     1 /* enum.c -- uses enumerated values */
     2 #include <stdio.h>
     3 #include <string.h>    // for strcmp()
     4 #include <stdbool.h>   // C99 feature
     5 
     6 enum spectrum {red, orange, yellow, green, blue, violet};
     7 const char * colors[] = {"red", "orange", "yellow",
     8                          "green", "blue", "violet"};
     9 #define LEN 30
    10 
    11 int main(void)
    12 {
    13     char choice[LEN];
    14     enum spectrum color;
    15     bool color_is_found = false;
    16 
    17     puts("Enter a color (empty line to quit):");
    18     while (gets(choice) != NULL && choice[0] != '')
    19     {
    20         for (color = red; color <= violet; color++)
    21         {
    22             if (strcmp(choice, colors[color]) == 0)
    23             {
    24                 color_is_found = true;
    25                 break;
    26             }
    27         }
    28         if (color_is_found)
    29             switch(color)
    30             {
    31                 case red    : puts("Roses are red.");
    32                               break;
    33                 case orange : puts("Poppies are orange.");
    34                               break;
    35                 case yellow : puts("Sunflowers are yellow.");
    36                               break;
    37                 case green  : puts("Grass is green.");
    38                               break;
    39                 case blue   : puts("Bluebells are blue.");
    40                               break;
    41                 case violet : puts("Violets are violet.");
    42                               break;
    43             }
    44         else
    45             printf("I don't know about the color %s.
    ", choice);
    46         color_is_found = false;
    47         puts("Next color, please (empty line to quit):");
    48     }
    49     puts("Goodbye!");
    50     
    51     return 0;
    52 }
  • 相关阅读:
    a标签href不跳转 禁止跳转
    重新安装 tcp/ip协议
    痤疮的治疗
    tuxedo 强制重启
    山西企业主要指标稳步回升 运行渐入平稳轨道
    unix/linux 环境软件调试笔记
    连连看消重算法
    oracle sql developer guide
    取某字段最大值所在的的记录
    食指的《相信未来》
  • 原文地址:https://www.cnblogs.com/lanjianhappy/p/6486928.html
Copyright © 2011-2022 走看看