Advertisement
Guest User

postal code exchanger

a guest
Apr 24th, 2013
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define TST_BIT(num, bit) ((1 << (bit)) & (num))
  5.  
  6. const char dig_mask[11][10] =
  7.     {{0x3f, 0x1,  0x3f, 0x3f, 0x21, 0x3f, 0x1,  0x3f, 0x3f, 0x3f},
  8.      {0x21, 0x3,  0x1,  0x2,  0x21, 0x20, 0x2,  0x2,  0x21, 0x21},
  9.      {0x21, 0x5,  0x1,  0x4,  0x21, 0x20, 0x4,  0x4,  0x21, 0x21},
  10.      {0x21, 0x9,  0x1,  0x8,  0x21, 0x20, 0x8,  0x8,  0x21, 0x21},
  11.      {0x21, 0x11, 0x1,  0x10, 0x21, 0x20, 0x10, 0x10, 0x21, 0x21},
  12.      {0x21, 0x21, 0x1,  0x3f, 0x3f, 0x3f, 0x3f, 0x20, 0x3f, 0x3f},
  13.      {0x21, 0x1,  0x2,  0x2,  0x1,  0x1,  0x21, 0x20, 0x21, 0x2 },
  14.      {0x21, 0x1,  0x4,  0x4,  0x1,  0x1,  0x21, 0x20, 0x21, 0x4 },
  15.      {0x21, 0x1,  0x8,  0x8,  0x1,  0x1,  0x21, 0x20, 0x21, 0x8 },
  16.      {0x21, 0x1,  0x10, 0x10, 0x1,  0x1,  0x21, 0x20, 0x21, 0x10},
  17.      {0x3f, 0x1,  0x3f, 0x20, 0x1,  0x3f, 0x3f, 0x20, 0x3f, 0x20}};
  18.  
  19. void print_digits(const char *digits);
  20.  
  21. int main (void)
  22. {
  23.     char postal_code[6] = {0};
  24.    
  25.     printf("Enter a postal code: ");
  26.     scanf("%6s", postal_code);
  27.     printf("\n\n");
  28.     print_digits(postal_code);
  29.  
  30.     system("pause > nul");
  31.     return 0;
  32. }
  33.  
  34. void print_digits(const char *digits)
  35. {
  36.     int i, j, z;
  37.     for (j = 0; j < 11; j++)
  38.     {
  39.         for (z = 0; digits[z]; z++)
  40.         {
  41.             for (i = 5; i >= 0; i--)
  42.                 printf("%c", TST_BIT(dig_mask[j][digits[z] - 48], i) ? 0xf9 : ' ');
  43.             printf("  ");
  44.         }
  45.         putchar('\n');
  46.     }          
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement