C vprintf, vfprintf, vsprintf, and vsnprintf
Syntax
C vprintf, vfprintf, vsprintf, and vsnprintf have the following syntax.
int vprintf(char *format, va_list arg_ptr);
int vfprintf(FILE *stream, const char *format, va_list arg_ptr);
int vsprintf(char *buf, const char *format, va_list arg_ptr);
int vsnprintf(char * restrict buf, size_t num, const char * restrict format, va_list arg_ptr);
Header
C vprintf, vfprintf, vsprintf, and vsnprintf
methods are from stdarg.h
and stdio.h
.
Description
The functions vprintf()
, vfprintf()
,
vsprintf()
, and vsnprintf()
are functionally equivalent to
printf()
, fprintf()
,
sprintf()
, and snprintf()
, respectively
,except that the argument list has been replaced by a pointer to a list of arguments.
This pointer must be of type va_list, which is defined in the header stdarg.h.
Example
#include <stdio.h>
#include <stdarg.h>
//from ww w . ja va2 s.c om
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;
}