Skip to content

Instantly share code, notes, and snippets.

@jitsceait
Last active August 29, 2015 14:00
Show Gist options
  • Save jitsceait/3e1f20664898084a5dca to your computer and use it in GitHub Desktop.
Save jitsceait/3e1f20664898084a5dca to your computer and use it in GitHub Desktop.
This program implements T9 dictionary
#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