Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C |
both |
#include <stdarg.h>
#include <stdio.h>
int vsprintf(char * __restrict__target-string,
const char * __restrict__format, va_list arg_ptr);
The vsprintf() function is similar to sprintf(), except that arg_ptr points to a list of arguments whose number can vary from call to call in the program. In contrast, sprintf() can have a list of arguments, but the number of arguments in that list is fixed when you compile the program. For a specification of the format string, see fprintf(), printf(), sprintf() — Format and write data.
If successful, vsprintf() returns the number of characters written target-string.
⁄* CELEBV05
This example assigns a variable number of strings to string
and prints the resultant string, using &vsprintf..
*⁄
#include <stdarg.h>
#include <stdio.h>
void vout(char *string, char *fmt, ...);
char fmt1 [] = "%s %s %s\n";
int main(void)
{
char string[100];
vout(string, fmt1, "Sat", "Sun", "Mon");
printf("The string is: %s\n", string);
}
void vout(char *string, char *fmt, ...)
{
va_list arg_ptr;
va_start(arg_ptr, fmt);
vsprintf(string, fmt, arg_ptr);
va_end(arg_ptr);
}
The string is: Sat Sun Mon