Updated: April 19, 2023 |
Write formatted output into an allocated string
#include <stdio.h> int asprintf( char **strp, const char *format, ... );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The asprintf() function formats data under control of the format control string. It's similar to sprintf(), except that asprintf() allocates a string for the formatted output. A null character is placed at the end of the generated character string. If asprintf() 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 counting the terminating null character, or a negative value if an 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 |