Current location: Hot Scripts Forums » Programming Languages » C/C++ » conversion of a keypad code to the responding characters


conversion of a keypad code to the responding characters

Reply
  #1 (permalink)  
Old 08-03-07, 03:08 AM
davids5a's Avatar
davids5a davids5a is offline
New Member
 
Join Date: Aug 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rolleyes conversion of a keypad code to the responding characters

cpp Code:
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. char num_char(int i, int j){
  5.     switch(i){
  6.         case '1': switch(j){
  7.                     case '1':   
  8.                     case '2'
  9.                     case '3':
  10.                     case '4':   return ' ';
  11.                                 break;
  12.                 }
  13.                 break;
  14.         case '2': switch(j){
  15.                     case '1':   return 'a';
  16.                                 break;   
  17.                     case '2':   return 'b';
  18.                                 break
  19.                     case '3':   return 'c';
  20.                                 break;
  21.  
  22.                 }
  23.                 break;
  24.         case '3': switch(j){
  25.                     case '1':   return 'd';
  26.                                 break;   
  27.                     case '2':   return 'e';
  28.                                 break
  29.                     case '3':   return 'f';
  30.                                 break;
  31.  
  32.                 }
  33.                 break;
  34.         case '4': switch(j){
  35.                     case '1':   return 'g';
  36.                                 break;   
  37.                     case '2':   return 'h';
  38.                                 break
  39.                     case '3':   return 'i';
  40.                                 break;
  41.  
  42.                 }
  43.                 break;
  44.         case '5': switch(j){
  45.                     case '1':   return 'j';
  46.                                 break;   
  47.                     case '2':   return 'k';
  48.                                 break
  49.                     case '3':   return 'l';
  50.                                 break;
  51.                 }
  52.                 break;
  53.         case '6': switch(j){
  54.                     case '1':   return 'm';
  55.                                 break;   
  56.                     case '2':   return 'n';
  57.                                 break
  58.                     case '3':   return 'o';
  59.                                 break;
  60.  
  61.                 }
  62.                 break;
  63.         case '7': switch(j){
  64.                     case '1':   return 'p';
  65.                                 break;   
  66.                     case '2':   return 'q';
  67.                                 break
  68.                     case '3':   return 'r';
  69.                                 break;
  70.                     case '4':   return 's';
  71.                                 break;
  72.                 }
  73.                 break;
  74.         case '8': switch(j){
  75.                     case '1':   return 't';
  76.                                 break;   
  77.                     case '2':   return 'u';
  78.                                 break
  79.                     case '3':   return 'v';
  80.                                 break;
  81.  
  82.                 }
  83.                 break;
  84.         case '9': switch(j){
  85.                     case '1':   return 'w';
  86.                                 break;   
  87.                     case '2':   return 'x';
  88.                                 break
  89.                     case '3':   return 'y';
  90.                                 break;
  91.                     case '4':   return 'z';
  92.                                 break;
  93.                 }
  94.                 break;
  95.     }
  96. }
  97.  
  98. int main(void){
  99.     int a; char b&#91;10]; int i, k;
  100.     printf("Vpisi kodo: "); scanf("%d", &a);
  101.     itoa(a,b,10);
  102.     for(k = 0; k < strlen(b); k++){
  103.         for(i = 0; i < 4; i++){
  104.             printf("%c", num_char(b&#91;k], i+1));
  105.         }
  106.         printf("\n");
  107.     }
  108.     system("pause");
  109.     return 0;
  110. }

This is the code I wrote so far. It should print 3 characters that correspond to each number but what it really does is print totally unwanted chars.
So if I input the number '34' it should print:
dg
dh
di
eg
eh
ei
fg
fh
fi

...or something like that... but it does not.

Does anyone know what's the problem?

Last edited by Nico; 08-03-07 at 10:31 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP inside JavaScript? pikaz JavaScript 20 07-10-10 01:55 AM
Wanted to replace special characters in MS Access using VB, but more than 1 character cebuy Visual Basic 3 12-04-05 06:30 PM
Have a look at my JSP code which is not giving me the desired output j.gohel Everything Java 1 04-07-05 04:55 AM
Disable form fields to be submitted RickyRod JavaScript 2 05-24-04 11:15 AM
How to sale php code to customer without giving him code pradeep_soft PHP 4 03-12-04 01:10 PM


All times are GMT -5. The time now is 01:26 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.