I'm trying to find a way to convert a number in any given base to decimal and then to the target base. What i'm asking is how will I represent this procedure in the function for example 123 base 4 to decimal= 1x4^2+2x4^1+3x4^0=27. I was thinking of decrementing the raised power with a for statement.But i'm also using a for statement to access each number in the string array. heres my attempt
#include<stdio.h>
int main(void)
{
char num_string;
int sourcebase;
int targetbase;
int temp
do {
printf("Enter a positive number/n");
scanf_s("%c",&num_string);
printf("Enter the base of that number");
scanf_s("%d", &sourcebase);
printf("Enter the destination base");
scanf_s("%d",&targetbase);
if((sourcebase<2)||(sourcebase>10)){
printf ("You number is invalid!!!!!!!/n/n");
}
}
length= //some code to get string length
for(i=0;i<length,i++)
temp=num_string[i]*sourcebase //here should be corresponding index