Pointer to the buffer where the formatted output string will be stored. The buffer must be large enough to hold the resulting string, including the null terminator.
2nd Parameter Type : const char *
Pointer to read-only string
2nd Parameter
Pointer to a null-terminated string specifying the format of the output. It may include format specifiers like `%d`, `%s`, etc.
3rd Parameter Type : va_list
A data type used to hold information about variable arguments passed to a variadic function. It is initialized with `va_start`, used with `va_arg`, and cleaned up with `va_end`.
3rd Parameter
The variable argument list containing the values to be formatted and written. It must be initialized with `va_start`.
Read more about parameters of vsprintf in parameters section
The vsprintffunction in C language Writes formatted output to a string using a va_list.
vsprintf is similar to sprintf, but instead of taking a variable number of arguments, it takes a va_list that has been initialized by va_start. This function writes the formatted data to the character string str. The resulting string is always null-terminated.
The vsprintffunction takes 3
parameters:
•
char * `str`: Pointer to the buffer where the formatted output string will be stored. The buffer must be large enough to hold the resulting string, including the null terminator.
•
const char * `format`: Pointer to a null-terminated string specifying the format of the output. It may include format specifiers like `%d`, `%s`, etc.
•
va_list `args`: The variable argument list containing the values to be formatted and written. It must be initialized with `va_start`.
Writes a formatted string to the buffer `str` based on the format string `format` and the values in the `va_list` object `args`. The resulting string is null-terminated. Returns the number of characters written, excluding the null terminator. If an encoding error occurs, a negative value is returned.
The vsprintf function return value :
Returns the number of characters written, not including the terminating null character
If an error occurs, a negative number is returned
Output
This example demonstrates using vsprintf in a custom function to format a string with various types of arguments.