Last active
August 29, 2015 14:00
-
-
Save jitsceait/3e1f20664898084a5dca to your computer and use it in GitHub Desktop.
This program implements T9 dictionary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define MAX_NUMBER_LENGTH 3 | |
const char hashTable[10][4] = {"", "", | |
"abc", "def", | |
"ghi", "jkl", | |
"mno", "pqrs", | |
"tuv", "wxyx"}; | |
void printWords(int number[], int curr_digit, char output[]){ | |
int i; | |
if(curr_digit == MAX_NUMBER_LENGTH){ | |
printf("%s\n", output); | |
return ; | |
} | |
for(i=0; i<strlen(hashTable[curr_digit]); i++){ | |
output[curr_digit] = hashTable[(number[curr_digit])][i]; | |
printWords(number, curr_digit+1, output); | |
if(number[curr_digit] == 0 || number[curr_digit] == 1) | |
return; | |
} | |
} | |
void T9_dictionary(int number[], int n){ | |
char result[n +1] ; | |
result[n] ='\0'; | |
printWords(number, 0, result); | |
} | |
/* Driver program to execute above code */ | |
int main(void) | |
{ | |
int number[] = {2, 3, 4}; | |
int n = sizeof(number)/sizeof(number[0]); | |
T9_dictionary(number,n) | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment