# Thread: How to change a number to char*? Like 50 --> "50"

1. ## How to change a number to char*? Like 50 --> "50"

How to do it in the simplest method?

2. sprintf

3. thank Salem!!!

4. I have a problem about precision multiplication. The code I wrote below.
Code:
```int charToInt(char x)
{ return (int)(x-'0'); }

char intToChar(int x)
{ return (char)(x+'0'); }

void reverse(char *x, int lenX)
{
int i;
char t;
for (i = 0; i < (int)(lenX/2); i++) {
t = x[i];
x[i] = x[lenX-i-1];
x[lenX-i-1] = t;
}
for (i = 0; i < lenX; i++)
printf("%c", x[i]);
printf("\n");
}

char *precMult(char *a, char *b, int *lenC, int lenA, int lenB)
{
int i, j, lenMax, lenMin;
int *tmp;
char *c;
lenMax = MAX(lenA, lenB);
lenMin = MIN(lenA, lenB);
tmp = malloc((lenA+lenB+1) * sizeof *tmp);
c = malloc((lenA+lenB+1) * sizeof *tmp);
reverse(a, lenA);
reverse(b, lenB);
for (i = 0; i < lenMax; i++)
tmp[i] = 0;
for (i = 0; i < lenMin; i++) {
for (j = 0; j < lenMax; j++) {
tmp[i+j] += charToInt(a[j])*charToInt(b[i]);
if (tmp[i+j] >= 10) {
tmp[i+j+1] += (int)tmp[i+j]/10;
tmp[i+j] %= 10;
}
}
}
*lenC = lenA+lenB-1;
if (tmp[lenA+lenB-1] > 0)
(*lenC)++;
for (i = *lenC-1; i >= 0; i--)
c[i] = intToChar(tmp[i]);
free(tmp);
return c;
}```
How to do a action like "a = precMult(b, c, lenB, lenC, &lenA)". a, b, c are array. lenA, lenB, lenC are int.

5. Umm . . . change the order of the arguments?

6. yes, dwks. I wanna change the order of arguments.

7. You're asking how you do that?
Code:
`printf("Hello, %s. You are %d years old.\n", name, age);`
->
Code:
`printf("Hello, %d-year-old %s.\n", age, name);`