
char linebuf[80];

char phonenum[80];		/* number string entered */

char letters[][3] = {

	'-','-','-',	/* 0 easy indexing */
	'-','-','-',	/* 1 easy indexing */
	'a','b','c',	/* 2 */
	'd','e','f',	/* 3 */
	'g','h','i',	/* 4 */
	'j','k','l',	/* 5 */
	'm','n','o',	/* 6 */
	'p','r','s',	/* 7 */
	't','u','v',	/* 8 */
	'w','x','y'	/* 9 */
};

int ctrs[10];		/* counters for each digit */
int digits;		/* number of digits */
int vowels;
int cons_in_a_row;
main () {

char *cp,*sp;
int carry;		/* carry past last digit */
char word[80];
int i;
char c;

	printf("Make word out of a phone number. T. Jennings 6 Oct 84\r\n");
	printf("\r\n");
	printf("The rules here are, you enter a string of digits, and you \r\n");
	printf("get a list of sort-of words, which you have to wade through\r\n");
	printf("to find real words. The more digits you enter, the more words.\r\n");
	printf("Numbers that contain '0' or '1' cannot be used, since there are\r\n");
	printf("no letters for those digits. (Look at your phone.) Words\r\n");
	printf("that have no vowels, or four or more consonants in a row\r\n");
	printf("are not displayed.\r\n");

	printf("Your number please: "); 
	if (getstring(linebuf) == 0) return;
	printf("\r\n");

	digits= 0;
	cp= linebuf; sp= phonenum;
	while (*cp) {
		if ((*cp == '0') || (*cp == '1')) {
			printf("Cant use 0 or 1\r\n");
			return;
		}
		if (isdigit(*cp)) {
			*sp++= *cp;
			++digits;
		}
		++cp;
	}
	*sp= '\0';
	if (digits < 1) {
		printf("you didnt enter any digits!\r\n");
		return;
	}
	if (digits > 10) {
		printf("Too many digits!\r\n");
		return;
	}

	printf("The number is %s\r\n",phonenum);

	carry= 0;
	while (! carry) {

		sp= word;
		vowels= 0;
		cons_in_a_row= 0;
		for (i= 0; i < digits; i++) {
			c= letters[phonenum[i] - '0'] [ctrs[i]];
			if ((c == 'a') || (c == 'e') || (c == 'i') ||
			  (c == 'o') || (c == 'u')) {
				++vowels;
				cons_in_a_row= 0;

			} else if (++cons_in_a_row > 3) break;
			*sp++= c;
		}
		*sp= '\0';

		if (vowels && (cons_in_a_row <= 3)) printf(" %s\r\n",word);

		for (i= 0; i < digits; i++) {
			if (++ctrs[i] < 3) break;
			ctrs[i]= 0;
		}
		if (i >= digits) ++carry;
	}
}

