AT&T UNIX™PC Unix System V Users Manual - tenox

AT&T UNIX™PC Unix System V Users Manual - tenox AT&T UNIX™PC Unix System V Users Manual - tenox

01.01.2013 Views

()·-

VPRINTF ( 3S ) VPRINTF ( 3S ) NAME vprintf, vfprintf, vsprintf - print formatted output of a varargs argument list SYNOPSIS #include #include int vprintf (format, ap) char *format; va_list ap; int vfprintf (stream, format, ap) FILE *stream; char *format; va_list ap; int vsprintf (s, format, ap) char *s, *format; va_list ap; DESCRIPTION Vp rintf, vfprintf, and vsprintf are the same as print/, fprintf, and sprint! respectively, except that instead of being called with a variable number of arguments, they are called with an argument list as defined by varargs(5). EXAMPLE The following demonstrates the use of vfprintf to write an error routine. #include #include /* /* error should be called like /* error(function_name, format, argl, arg2 . . • ); *I I* v ARARGS *I void error( va_alist) I* Note that the function_name and format arguments cannot be /* separately declared because of the definition of varargs. *I va_dcl { va_list args; char *fmt; va_start( args); /* print out name of function causing error *I (void)fprintf(stderr, "ERROR in %s: ", va_arg(args, char *)); fmt = va_arg(args, char *); /* print out remainder of message *I (void)vfprintf(stderr, fmt, args); va_end( args ); (void)abort( ); - 1 -

VPRINTF ( 3S ) VPRINTF ( 3S )<br />

NAME vprintf, vfprintf, vsprintf - print formatted output of a varargs<br />

argument list<br />

SYNOPSIS<br />

#include <br />

#include <br />

int vprintf (format, ap)<br />

char *format;<br />

va_list ap;<br />

int vfprintf (stream, format, ap)<br />

FILE *stream;<br />

char *format;<br />

va_list ap;<br />

int vsprintf (s, format, ap)<br />

char *s, *format;<br />

va_list ap;<br />

DESCRIPTION<br />

Vp rintf, vfprintf, and vsprintf are the same as print/, fprintf, and<br />

sprint! respectively, except that instead of being called with a<br />

variable number of arguments, they are called with an argument<br />

list as defined by varargs(5).<br />

EXAMPLE<br />

The following demonstrates the use of vfprintf to write an error<br />

routine.<br />

#include <br />

#include <br />

/*<br />

/* error should be called like<br />

/* error(function_name, format, argl, arg2 . . • ); *I<br />

I* v ARARGS *I<br />

void<br />

error( va_alist)<br />

I* Note that the function_name and format arguments cannot be<br />

/* separately declared because of the definition of varargs. *I<br />

va_dcl<br />

{<br />

va_list args;<br />

char *fmt;<br />

va_start( args);<br />

/* print out name of function causing error *I<br />

(void)fprintf(stderr, "ERROR in %s: ", va_arg(args, char *));<br />

fmt = va_arg(args, char *);<br />

/* print out remainder of message *I<br />

(void)vfprintf(stderr, fmt, args);<br />

va_end( args );<br />

(void)abort( );<br />

- 1 -

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!