- Parameters: number -- the number you are converting a string
- base -- the base you are converting the numebr to
- Return: The number as a string in base "base"
- Return Type: char *
This is my code but it is not working;
char *toBase(int number, int base) {
char *result=malloc(80);
char *ans=malloc(80);
int i=0,j,c;
while(number != 0) {
result[i] = number % base;
number = number / base; ++i;
}
for(j=i-1;j>=0;j--) {
if(result[j]>=10 && result[j]<=24) {
printf("%c",(result[j]+55));
*ans++=(result[j]+55);
} else {
printf("%d",(result[j]));
*ans++=(result[j]);
}
}
return ans;
}