home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume1 / 8708 / 2 < prev    next >
Encoding:
Internet Message Format  |  1990-07-13  |  1.9 KB

  1. From: bobk@mntgfx.MENTOR.COM (Bob Kelley)
  2. Newsgroups: comp.sources.misc
  3. Subject: Program to enumerate all words derivable from a telephone number
  4. Keywords: telephone mnemonic
  5. Message-ID: <3747@ncoast.UUCP>
  6. Date: 5 Aug 87 00:28:33 GMT
  7. Sender: allbery@ncoast.UUCP
  8. Organization: Mentor Graphics, Beaverton OR
  9. Lines: 62
  10. Approved: allbery@ncoast.UUCP
  11. X-Archive: comp.sources.misc/8708/2
  12.  
  13. /*
  14.  * enumerate all words derivable from a telephone number - phony.c
  15.  *
  16.  * Usage: phony <telephone number less than 32 characters>
  17.  *
  18.  * Non-digits, '0', and '1' in the phone number are transcripted as is.
  19.  * The digits '2' through '9' are cycled through their letter equivalents.
  20.  *
  21.  * I don't care what you do with this program, which was inspired by a
  22.  * telephone number which I found impossible to remember.  Robert J. Kelley 8/3/87
  23.  */
  24.  
  25. #include <stdio.h>
  26.  
  27. char *digits[] = { "abc",
  28.                    "def",
  29.                    "ghi",
  30.                    "jkl",
  31.                    "mno",
  32.                    "prs",
  33.                    "tuv",
  34.                    "wxy" };
  35.  
  36. char    buf[32];
  37.  
  38. enumerate (s, b)
  39.         char    *s;
  40.         char    *b;
  41. {
  42.         char    *p;
  43.  
  44.         if (b >= buf + sizeof(buf)) {
  45.                 printf ("phony: Telephone number longer than 32 characters.\n");
  46.                 exit (1);
  47.         }
  48.  
  49.         if (*s == 0)
  50.                 printf ("%s\n", buf);
  51.         else if ('2' <= *s && *s <= '9') {
  52.                 for (p = digits[*s - '2']; *p; ++p) {
  53.                         *b = *p;
  54.                         enumerate (s + 1, b + 1);
  55.                 }
  56.        } else {
  57.                 *b = *s;
  58.                 enumerate (s + 1, b + 1);
  59.         }
  60. }
  61.  
  62. main (argc, argv)
  63.         int     argc;
  64.         char    **argv;
  65. {
  66.         char    *s;
  67.  
  68.         if (argc != 2) {
  69.                 printf ("usage: phony <phone number>\n");
  70.                 exit (1);
  71.         }
  72.  
  73.         enumerate (argv[1], buf);
  74. }
  75.  
  76.  
  77.