Vprintf, Example, Synopsis – Zilog ZUSBOPTS User Manual
Page 484: Returns

Standard Functions
UM017105-0511
456
Zilog Developer Studio II – ZNEO™
User Manual
Example
The function f1 gathers into an array a list of arguments that are pointers to strings (but not
more than MAXARGS arguments), then passes the array as a single argument to function
f2. The number of pointers is specified by the first argument to f1.
#include
extern void f2(int n, char *array[]);
#define MAXARGS 31
void f1(int n_ptrs,...) {
va_list ap;
char *array[MAXARGS];
int ptr_no = 0;
if (n_ptrs > MAXARGS)
n_ptrs = MAXARGS;
va_start(ap, n_ptrs);
while (ptr_no < n_ptrs)
array[ptr_no++] = va_arg(ap, char *);
va_end(ap);
f2(n_ptrs, array);
}
Each call to f1 has in scope the definition of the function of a declaration such as
void
f1(int, ...);
vprintf
Equivalent to
printf
, with the variable argument list replaced by arg, which has been ini-
tialized by the
va_start
macro (and possibly subsequent
va_arg
calls). The
vprintf
function does not invoke the
va_end
function.
Synopsis
#include
#include
int vprintf(const char *format, va_list arg);
Returns
The number of characters transmitted or a negative value if an output error occurred.
Example
va_list va;
/* initialize the variable argument va here */
vprintf("%d %d %d",va);