Updated: April 19, 2023 |
Write formatted output into an allocated string (varargs)
#include <stdio.h> #include <stdarg.h> int vasprintf( char **strp, const char *format, va_list arg );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The vasprintf() function formats data under control of the format control string. It's a varargs version of asprintf() and is similar to sprintf(), except that vasprintf() allocates a string for the formatted output. A null character is placed at the end of the generated character string. If vasprintf() is successful, it sets *strp to point to the string.
You should call free() to free the string when you're finished with it.
The number of characters written into the string, not including the terminating null character, or a negative value if an output error occurred (errno is set, and *strp is left unchanged). An error can occur while converting a value for output.
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |