-2
I’m asking the question Voice Dial, I’ve done every test possible and can’t find the error could help me in other test that my code fails
My code
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int indice(char *numero);
void printa(char n);
int main(int argc, char** argv)
{
char numero[900];
int tam, resultado, i;
while(gets(numero) != NULL)
{
tam = strlen(numero);
if(indice(numero))
{
resultado = indice(numero);
resultado--;
for(i = 0; i < resultado; i++)
{
printf("%c", numero[i]);
}
for(i = resultado; i < tam ; i++)
{
printa(toupper(numero[i]));
}
printf("\n");
}
else
{
for(i = 0; i < tam; i++)
{
if((numero[i] >= '0' && numero[i] <= '9') || numero[i] == '*' || numero[i] == '#')
{
printf("%c", numero[i]);
}
}
printf("\n");
}
}
return 0;
}
int indice(char *numero)
{
int tam = strlen(numero), i, j, resultado = 0;
char alfabeto[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"};
int tam2 = strlen(alfabeto);
for(i = 0; i < tam; i++)
{
for(j = 0; j < tam2 ; j++)
{
if(numero[i] == alfabeto[j])
{
resultado = i;
break;
}
}
if(resultado > 0)
{
break;
}
}
return resultado;
}
void printa(char n)
{
if(n == 'A' || n == 'B' || n == 'C')
{
printf("2");
}
else if(n == 'D' || n == 'E' || n == 'F')
{
printf("3");
}
else if(n == 'G' || n == 'H' || n == 'I')
{
printf("4");
}
else if(n == 'J' || n == 'K' || n == 'L')
{
printf("5");
}
else if(n == 'M' || n == 'N' || n == 'O')
{
printf("6");
}
else if(n == 'P' || n == 'Q' || n == 'R' || n == 'S')
{
printf("7");
}
else if(n == 'T' || n == 'U' || n == 'V')
{
printf("8");
}
else if(n == 'W' || n == 'X' || n == 'Y' || n == 'Z')
{
printf("9");
}
}
Friend, if you don’t give a damn what that code is supposed to do or what parts are not working well, how do you expect us to tell you what is wrong ? Remember that the clearer and more detailed you are, the more likely you are to have an answer that suits you
– Isac
To the entrance
T800-RAFO0
, the program goes wrong.– Marcelo Shiniti Uchimura