Well I'm making the question 1199 Conversion of uri bases but in some cases my test passed, but when I put a number that the staff put in the forum gave error, the number was 0x80000000 the expected result is 2147483648, except that my code prints -2147483648, I already tried to multiply by -1 and the result continued negative, could anyone help me
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
char saber_o_tipo(char *numero);
int main(int argc, char** argv)
{
char *numero;
numero = (char*)malloc(sizeof(char) * 1000000);
int resposta, valor;
while(1)
{
scanf("%s", numero);
if(numero[0] == '-')
{
break;
}
resposta = saber_o_tipo(numero);
if(resposta > 0)
{
sscanf(numero, "%x", &valor);
if(valor < 0)
{
printf("%d\n", valor*-1);
}
else
{
printf("%d\n", valor);
}
}
else
{
sscanf(numero, "%d", &valor);
printf("Ox%X\n", valor);
}
}
free(numero);
return 0;
}
char saber_o_tipo(char *numero)
{
int i, contador = 0, tamanho;
tamanho = strlen(numero);
for(i = 0; i < tamanho; i++)
{
if(isalpha(numero[i]))
{
contador++;
}
}
if(contador > 0)
{
return 1;
}
else
{
return 0;
}
}