2
I’m trying to program a phone algorithm with the old keys where the user will enter the letters as input and output will return me in the form of numbers. Note an example below:
Input: Hello-World
Output: 43556-96753
I tried with the code below, but only returns me the number of the first letter of the word
#include <stdio.h>
#include <stdlib.h>
int main(){
    char texto[30];
    printf("Pressione A B C para 2");
    printf("\nPressione D E F para 3");
    printf("\nPressione G H I para 4");
    printf("\nPressione J K L para 5");
    printf("\nPressione M N O para 6");
    printf("\nPressione P Q R S para 7");
    printf("\nPressione T U V para 8");
    printf("\nPressione W X Y Z para 9");
    printf("\n\nInforme as letras: ");
    gets(texto);
    char *ptr;
    ptr = strtok(texto, "-");
    while (ptr != NULL){
        if (*ptr == 'A' || *ptr == 'B' || *ptr == 'C'){
            printf("2");
        }
        else if (*ptr == 'D' || *ptr == 'E' || *ptr == 'F'){
            printf("3");
        }
        else if (*ptr == 'G' || *ptr == 'H' || *ptr == 'I'){
            printf("4");
        }
        else if (*ptr == 'J' || *ptr == 'K' || *ptr == 'L'){
            printf("5");
        }
        else if (*ptr == 'M' || *ptr == 'N' || *ptr == 'O'){
            printf("6");
        }
        else if (*ptr == 'P' || *ptr == 'Q' || *ptr == 'R' || *ptr == 'S'){
            printf("7");
        }
        else if (*ptr == 'T' || *ptr == 'U' || *ptr == 'V'){
            printf("8");
        }
        else if (*ptr == 'W' || *ptr == 'X' || *ptr == 'Y' || *ptr == 'Z'){
            printf("9");
        }
        ptr = strtok(NULL, "-");
    }
    return 0;
}