asprintf
(3)print to allocated string
#define _GNU_SOURCE /* See feature_test_macros(7) */ #include <stdio.h> int asprintf(char **restrict strp, const char *restrict fmt, ...); int vasprintf(char **restrict strp, const char *restrict fmt, va_list ap);
LIBRARY
DESCRIPTION
The functions asprintf() and vasprintf() are analogs of sprintf(3) and vsprintf(3), except that they allocate a string large enough to hold the output including the terminating null byte ('\0'), and return a pointer to it via the first argument. This pointer should be passed to free(3) to release the allocated storage when it is no longer needed.