So im having trouble with creating a recursive function to convert a number from bases 2-10 to bases 2-16. I need it to return a string (obviously , due to the bases greater than 10).
here is my function:
main would call it like:
answer = baseConversion(101, 10, 2);
I have hex as a constant char:
const char Hex[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
char * baseConverter(int number,int currbase, int base){
if(currbase != 10){
number = base10Converter(number, currbase); //converts the number to base of 10
currbase = 10;
}
if(number == 0 || base==10){
return number;
}
int r = number%base;
printf("%c", Hex[r]);
//return (number % base) + 10*baseConverter(number /base, currbase, base); // this gives the answer as an integer.
return Hex[r]+ && baseConverter(number /base, currbase, base) // I dont know what to add here to add the characters together
}
i need help with my return statement and recursive call. Do i need to declare a char array within the function and then append the chars i get from hex[r] to it? If so, How do i go about doing that because I cant change the parameters