home *** CD-ROM | disk | FTP | other *** search
- From: bobk@mntgfx.MENTOR.COM (Bob Kelley)
- Newsgroups: comp.sources.misc
- Subject: Program to enumerate all words derivable from a telephone number
- Keywords: telephone mnemonic
- Message-ID: <3747@ncoast.UUCP>
- Date: 5 Aug 87 00:28:33 GMT
- Sender: allbery@ncoast.UUCP
- Organization: Mentor Graphics, Beaverton OR
- Lines: 62
- Approved: allbery@ncoast.UUCP
- X-Archive: comp.sources.misc/8708/2
-
- /*
- * enumerate all words derivable from a telephone number - phony.c
- *
- * Usage: phony <telephone number less than 32 characters>
- *
- * Non-digits, '0', and '1' in the phone number are transcripted as is.
- * The digits '2' through '9' are cycled through their letter equivalents.
- *
- * I don't care what you do with this program, which was inspired by a
- * telephone number which I found impossible to remember. Robert J. Kelley 8/3/87
- */
-
- #include <stdio.h>
-
- char *digits[] = { "abc",
- "def",
- "ghi",
- "jkl",
- "mno",
- "prs",
- "tuv",
- "wxy" };
-
- char buf[32];
-
- enumerate (s, b)
- char *s;
- char *b;
- {
- char *p;
-
- if (b >= buf + sizeof(buf)) {
- printf ("phony: Telephone number longer than 32 characters.\n");
- exit (1);
- }
-
- if (*s == 0)
- printf ("%s\n", buf);
- else if ('2' <= *s && *s <= '9') {
- for (p = digits[*s - '2']; *p; ++p) {
- *b = *p;
- enumerate (s + 1, b + 1);
- }
- } else {
- *b = *s;
- enumerate (s + 1, b + 1);
- }
- }
-
- main (argc, argv)
- int argc;
- char **argv;
- {
- char *s;
-
- if (argc != 2) {
- printf ("usage: phony <phone number>\n");
- exit (1);
- }
-
- enumerate (argv[1], buf);
- }
-
-
-