C vprintf()

The vprintf() function is functionally equivalent to printf() except that the argument list has been replaced by a pointer to a list of arguments. This pointer must be of type va_list. va_list is defined in the header <stdarg.h>.

vprintf() Syntax

int vprintf(char *format, va_list arg_ptr);

vprintf() Example

Following c code fragments shows how to set up a call to the vprintf(). The call to the va_start() creates a variable-length arguments pointer to the start of the argument list. This pointer must be used in the call to the vprintf(). The call to the va_end() clears the variable-length argument pointer.

void print_message(char *format, ...);
void main()
	print_message("Cannot open file %s", "test");
void print_message(char *format, ...)
	va_list ptr;  /* get an arg ptr */
	/* initialize ptr to point to the first argument after the
	format string */
	va_start(ptr, format);
	/* print out message */
	vprintf(format, ptr);

C Online Test

« Previous Function Next Function »

Like/Share Us on Facebook 😋