vprintf, vfprintf, vsprintf - print formatted output
#include <stdio.h>
The vprintf(), vfprintf(), and vsprintf() functions are equivalent to printf(), fprintf()and sprintf() respectively, except that instead of being called with a variable number of arguments, they are called with an argument list as defined by <stdarg.h>.
vprintf() places output on the standard output stream stdout .
vfprintf() places output on strm.
vsprintf() places output, followed by the null character (0), in consecutive bytes starting at s. It is the user's responsibility to ensure that enough storage is available.
Each function returns the number of characters transmitted (not including the 0 in the case of vsprintf()) ) or a negative value if an output error was encountered.
Characters generated by vprintf() and vfprintf() are printed as if the fputc() routine had been called.
Refer to fprintf().
Refer to fprintf().
#include <stdio.h>
#include <stdarg.h>
void print_message(char *format, ...)
{
va_list ptr;
va_start(ptr, format);
vprintf(format, ptr);
va_end(ptr);
}
int main(void)
{
print_message("Cannot open file %s.", "test");
return 0;
}