I need help in making the character array str[] in mips and also reading out that array. I have to functions where I ask the user to enter a base between 2 and 36 and then prompt them to enter a number in that base and that number is converted to base 10(decimal).
int convert2dec(char *str, int base)
{
int j, val;
val = 0;
j = 0;
while (str[j] > 13) {
if (str[j] > 57)
val = val * base + str[j]-87;
else
val = val * base + str[j] - 48;
j++;
}
return val;
}
int main(int argc, char *argv[])
{
int X;
char str[256];
printf("Please the base (between 2 and 36 in decimal): ");
scanf("%d", &X);
printf("Please a number base %d: ", X);
scanf("%s", str);
printf("The decimal value is %d\n", convert2dec(str,X));
return 0;
}