编程基本功:基于switch语句的译码器

   1: #include "stdio.h"
   2:  
   3: void Decode(char *str, int n);
   4:  
   5: int main()
   6: {
   7:     char str[19] = "001011101001011001";
   8:     Decode(str, 18);
   9:     getchar();
  10:  
  11:     return 0;
  12: }
  13:  
  14: void Decode(char *str, int n)
  15: {
  16:     int i = 0;
  17:     while (i < n)
  18:     {
  19:         switch (str[i])
  20:         {
  21:             case '1':
  22:                 printf("a");
  23:                 break;
  24:             case '0':
  25:             {
  26:                 i++;
  27:                 switch (str[i])
  28:                 {
  29:                     case '1':
  30:                         printf("b");
  31:                         break;
  32:                     case '0':
  33:                     {
  34:                         i++;
  35:                         switch(str[i])
  36:                         {
  37:                             case '1':
  38:                                 printf("c");
  39:                                 break;
  40:                         }
  41:                         break;
  42:                     }
  43:                 }
  44:                 break;
  45:             }
  46:         }
  47:         i++;
  48:     }
  49: }
原文地址:https://www.cnblogs.com/steven_oyj/p/1742454.html