Advertisement
rdsedmundo

encotel.c

Jul 2nd, 2013
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.13 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int telSwitch(char chr) {
  5.     if(isdigit(chr))
  6.         return chr - '0';
  7.  
  8.     int aux = (int) chr;
  9.     if(aux >= 65 && aux <= 67)
  10.         return 2;
  11.     else if(aux >= 68 && aux <= 70)
  12.         return 3;
  13.     else if(aux >= 71 && aux <= 73)
  14.         return 4;
  15.     else if(aux >= 74 && aux <= 76)
  16.         return 5;
  17.     else if(aux >= 77 && aux <= 79)
  18.         return 6;
  19.     else if(aux >= 80 && aux <= 83)
  20.         return 7;
  21.     else if(aux >= 84 && aux <= 86)
  22.         return 8;
  23.     else if(aux >= 87 && aux <= 90)
  24.         return 9;
  25.  
  26.     return -1;
  27. }
  28.  
  29. int main(void) {
  30.     char Telefones[1024][1024];
  31.  
  32.     int i, j;
  33.  
  34.     for(i = 0; i < (1024); i++)
  35.         strcpy(Telefones[i], "");
  36.  
  37.     i = 0;
  38.     while(1) {
  39.         char Telaux[1024];
  40.         scanf("%s", Telaux);
  41.  
  42.         if(feof(stdin))
  43.             break;     
  44.  
  45.         strcpy(Telefones[i], Telaux);
  46.         i++;   
  47.     }
  48.  
  49.     for(i = 0; i < (1024); i++) {
  50.         if(strcmp(Telefones[i], "") == 0)
  51.             break;
  52.        
  53.         for(j = 0; j < strlen(Telefones[i]); j++) {
  54.             char currentChar = Telefones[i][j];
  55.             if(currentChar == '-')
  56.                 printf("-");
  57.             else
  58.                 printf("%d", telSwitch(currentChar));
  59.  
  60.             if((j+1) == strlen(Telefones[i]))
  61.                 printf("\n");
  62.         }
  63.     }
  64.  
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement