When converting an integer to text, typically I create a big buffer to use with sprintf() to hold any potential result.
sprintf()
char BigBuffer[50];
asprintf() is handy, it takes a char ** and uses malloc() to get the needed space so you need to free() it later.
No need to worry about how much space you need.
int asprintf(char **ret, const char *format, ...); char *p asprintf(&p, "%XXXX", ...); : : free(p);