codescracker


c

C vprintf()



« Previous Function Next Function »


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

#include<stdio.h>
#include<stdarg.h>
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.

#include<stdio.h>
#include<conio.h>
#include<stdarg.h>
void print_message(char *format, ...);
void main()
{
	clrscr();
	print_message("Cannot open file %s", "test");
	getch();
}
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);
	
	va_end(ptr);
}

« Previous Function Next Function »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test