hi....can anyone pliz tell me how to go about converting numbers to letters on a telephone keypad......

eg when we txt..and suppose we type in 4663,we can get hood,home,good,gone....etc...
got a project due!!!!!!!!!


prefer it in C

well,wat i have done switch break statement where we can convert from characters to num....but frankly no idea on how to go reverse....

#include <stdio.h>
#include <stdlib.h>


int main()
{
 int sentence;
 int scount = 0;/*Counts if the characters are less or equal to 80*/

/*Warns the user to only enter alphabets or space*/
 printf("Enter your sentence:");
 printf("(You can enter either uppercase or \nlowercase alphabets!!");
 printf("Entering anything other than alphabets \nand ");
 printf("spaces will terminate program!\n");
 
   while (((sentence=getchar())!='\0')&& scount<=81)
    {

       switch (sentence)
       {

          case 'A':
          case 'a':
          case 'B':
          case 'b':
	      case 'C':
          case 'c':
            ++sPtr;
            printf("2");
            break;

          case 'D':
          case 'd':
          case 'E':
          case 'e':
	      case 'F':
          case 'f':
	        ++sPtr;
            printf( "3");
            break;

          case 'G':
          case 'g':
          case 'H':
          case 'h':
	      case 'I':
          case 'i':
	      ++sPtr;
            printf("4");
            break;

          case 'J':
          case 'j':
          case 'K':
          case 'k':
	      case 'L':
          case 'l':
            ++sPtr;
            printf("5");
            break;

          case 'M':
          case 'm':
          case 'N':
          case 'n':
          case 'O':
          case 'o':
            ++sPtr;
            printf( "6");
            break;

          case 'P':
          case 'p':
          case 'Q':
          case 'q':
	      case 'R':
          case 'r':
          case 'S':
          case 's':
          ++sPtr;
            printf("7");
            break;

          case 'T':
          case 't':
          case 'U':
          case 'u':
          case 'V':
          case 'v':
            ++sPtr;
            printf("8");
            break;

          case 'W':
          case 'w':
          case 'X':
          case 'x':
          case 'Y':
          case 'y':
          case 'Z':
          case 'z':
           ++sPtr;
            printf("9");
            break;

          case ' ':
            ++scount;
            printf("1");
            break;
            
          case '\n': 
          case '\t': 
            printf("\n");
            break; 
            
          default:   
          exit(EXIT_SUCCESS);  /*Ends program if encounters anything other 
                               than alphabets or spaces*/
         
      }   /*exit switch*/
  
    }/*exit while*/
  
  return 0;
}

<< moderator edit: added [code][/code] tags >>

hi....can anyone pliz tell me how to go about converting numbers to letters on a telephone keypad......

eg when we txt..and suppose we type in 4663,we can get hood,home,good,gone....etc...

The code you posted seems to be going the other way -- from "home" to 4663.

This article has been dead for over six months. Start a new discussion instead.