So, with my beginner level of experience in C I've been trying to write a code that converts hexadecimal input to a decimal with an array. I believe you will get it more spesificly by looking at my code but it does not work properly. I keep getting an amount that is much larger than intended.
#include <stdio.h>
int main()
{
int i, k, j, N, power, result;
char array[50];
result = 0;
printf("how many charecters are there in your hexadecimal input?: \n");
scanf("%d", &N);
for(k=0; k<=N-1; k++)
{
printf("What is the %d . value of your hexadecimal input?: \n", k+1);
scanf("%s", &array[k]);
}
for(i=0; i<=N-1; i++)
{
power = 1;
for(j=0; j<=i; j++)
{
power = power *16;
}
if((array[i] >= 0) && (array[i] <= 9))
{
result = result + array[i] * power;
}
else
{
result = result + (array[i] - 'A' + 10) * power;
}
}
printf("your result is %d", result);
return 0;
}