Advertisement
dmilicev

decode_string.c

Apr 14th, 2021
687
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.12 KB | None | 0 0
  1. /*
  2.  
  3.     decode_string.c
  4.  
  5.     Task:
  6.     https://www.facebook.com/dmilicev/posts/4081967018490924:53
  7.  
  8.  
  9.     You can find all my C programs at Dragan Milicev's pastebin:
  10.  
  11.     https://pastebin.com/u/dmilicev
  12.  
  13. */
  14.  
  15. #include <stdio.h>
  16. #include <string.h>
  17.  
  18. int main(void)
  19. {
  20.     int i=0;
  21.     char str[]= "TR.XX";
  22.  
  23.     printf("\n%s\n\n",str);
  24.  
  25.     while( str[i] )     // for all characters of coded string
  26.     {
  27.         switch( str[i] )    // use switch-case to display proper values
  28.         {
  29.             case 'X' :
  30.                     printf("%d",0);
  31.                     break;
  32.             case 'C' :
  33.                     printf("%d",1);
  34.                     break;
  35.             case 'O' :
  36.                     printf("%d",2);
  37.                     break;
  38.             case 'M' :
  39.                     printf("%d",3);
  40.                     break;
  41.             case 'P' :
  42.                     printf("%d",4);
  43.                     break;
  44.             case 'U' :
  45.                     printf("%d",5);
  46.                     break;
  47.             case 'T' :
  48.                     printf("%d",6);
  49.                     break;
  50.             case 'E' :
  51.                     printf("%d",7);
  52.                     break;
  53.             case 'R' :
  54.                     printf("%d",8);
  55.                     break;
  56.             case 'S' :
  57.                     printf("%d",9);
  58.                     break;
  59.             default :   // in default, display same value.
  60.                     printf("%c",str[i]);
  61.                     break;
  62.         } // switch()
  63.         i++;
  64.     } // while()
  65.  
  66.     printf("\n");
  67.  
  68.     return 0;
  69.  
  70. } // main()
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement