home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / qc_prog / chap08 / phword.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-05  |  2.1 KB  |  76 lines

  1. /* phword.c   --  generate all the possible words     */
  2. /*                in a phone number; demonstrates     */
  3. /*                functions that return addresses     */
  4.  
  5. #define MAXD (7)    /* 7 digits max */
  6.  
  7. main()
  8. {
  9.     int digits[MAXD], ndigits = 0, line = 0;
  10.     char *letters; 
  11.     signed char digit;
  12.     int a, b, c, d, e, f, g;
  13.     extern char *Range();
  14.  
  15.     printf("Enter Phone Number (7 digits): ");
  16.     do
  17.         {
  18.         digit = getch() - '0';
  19.         if (digit == ('-' - '0'))
  20.             continue;
  21.         if (digit < 0 || digit > 9)
  22.             {
  23.             printf("\nAborted: Non Digit\n");
  24.             return(1);
  25.             }
  26.         digits[ndigits++] = digit;
  27.         printf("%d", digit);
  28.         } while (ndigits < 7);
  29.     printf("\n");
  30.  
  31.     for( a = 0; a < 3; ++a)
  32.      for( b = 0; b < 3; ++b)
  33.       for( c = 0; c < 3; ++c)
  34.        for( d = 0; d < 3; ++d)
  35.         for( e = 0; e < 3; ++e)
  36.          for( f = 0; f < 3; ++f)
  37.           for( g = 0; g < 3; ++g)
  38.               {
  39.               printf("%c", Range(digits[0])[a]);
  40.               printf("%c", Range(digits[1])[b]);
  41.               printf("%c", Range(digits[2])[c]);
  42.               printf("%c", Range(digits[3])[d]);
  43.               printf("%c", Range(digits[4])[e]);
  44.               printf("%c", Range(digits[5])[f]);
  45.               printf("%c", Range(digits[6])[g]);
  46.               printf("\n");
  47.               if (++line == 20)
  48.                   {
  49.                   printf("Press Any key for More");
  50.                   printf(" (or q to quit): ");
  51.                   if (getch() == 'q')
  52.                       return (0);
  53.                   printf("\n");
  54.                   line = 0;
  55.                   }
  56.               }
  57. }
  58.  
  59. char *Range(int key)
  60.     {
  61.     static char keys[10][3] = {
  62.         {'0', '0', '0' },
  63.         {'1', '1', '1' },
  64.         {'a', 'b', 'c' },
  65.         {'d', 'e', 'f' },
  66.         {'g', 'h', 'i' },
  67.         {'j', 'k', 'l' },
  68.         {'m', 'n', 'o' },
  69.         {'p', 'r', 's' },
  70.         {'t', 'u', 'v' },
  71.         {'w', 'x', 'y' }
  72.     };
  73.  
  74.     return (keys[key]);
  75. }
  76.