101 lines
2.5 KiB
Plaintext
101 lines
2.5 KiB
Plaintext
'\"macro stdmacro
|
|
.if n .pH g3s.vprintf @(#)vprintf 30.2 of 12/25/85
|
|
.nr X
|
|
.if \nX=0 .ds x} VPRINTF 3S "C Programming Language Utilities" "\&"
|
|
.if \nX=1 .ds x} VPRINTF 3S "C Programming Language Utilities"
|
|
.if \nX=2 .ds x} VPRINTF 3S "" "\&"
|
|
.if \nX=3 .ds x} VPRINTF "" "" "\&"
|
|
.TH \*(x}
|
|
.SH NAME
|
|
vprintf, vfprintf, vsnprintf, vsprintf \- print formatted output of a variable argument list
|
|
.SH SYNOPSIS
|
|
.B "#include <stdarg.h>"
|
|
.br
|
|
.B "#include <stdio.h>"
|
|
.PP
|
|
.B "int vprintf (const char \(**format, va_list arg);
|
|
.PP
|
|
.B "int vfprintf (\s-1FILE\s+1 \(**stream, const char \(**format, va_list arg);
|
|
.PP
|
|
.B "int vsnprintf (char \(**s, ssize_t len, const char \(**format, va_list arg);
|
|
.PP
|
|
.B "int vsprintf (char \(**s, const char \(**format, va_list arg);
|
|
.SH DESCRIPTION
|
|
.IR vprintf ,
|
|
.IR vfprintf ,
|
|
.IR vsnprintf ,
|
|
and
|
|
.I vsprintf\^
|
|
are the same as
|
|
.IR printf ,
|
|
.IR fprintf ,
|
|
.IR snprintf ,
|
|
and
|
|
.I sprintf\^
|
|
respectively,
|
|
except that instead of being called with a variable number of
|
|
arguments, they are called with an argument list,
|
|
.IR arg ,
|
|
as defined by
|
|
.IR stdarg (5).
|
|
The
|
|
.I arg
|
|
parameter must be initialized by the
|
|
.I va_start
|
|
macro (and possibly subsequent
|
|
.I va_arg
|
|
calls). The
|
|
.IR vprintf ,
|
|
.IR vfprintf ,
|
|
.IR vsnprintf ,
|
|
and
|
|
.I vsprintf
|
|
functions do not invoke the
|
|
.I va_end
|
|
macro.
|
|
.SH EXAMPLE
|
|
The following demonstrates the use of
|
|
.I vfprintf
|
|
to write an error routine.
|
|
.PP
|
|
The \f2stdarg.h\fP header file defines the
|
|
type \f2va_list\fP and a set of macros for advancing
|
|
through a list of arguments whose number and types may vary.
|
|
The argument \f2ap\fP to the vprint family of
|
|
routines is of type \f2va_list\fP.
|
|
This argument is used with the \f2stdarg.h\fP header
|
|
file macros \f2va_start\f1, \f2va_arg\fP and \f2va_end\fP
|
|
[see \f2va_start\fP, \f2va_arg\fP, and \f2va_end\fP
|
|
in \f2stdarg\fP(5)].
|
|
.PP
|
|
.nf
|
|
.ss 18
|
|
#include <stdio.h>
|
|
#include <stdarg.h>
|
|
.sp
|
|
/\(**
|
|
\(** error should be called as:
|
|
\(** error(function_name, format, arg1, arg2 .\|.\|.);
|
|
\(**/
|
|
void
|
|
error(char \(**function_name, char \(**format, ...)
|
|
{
|
|
va_list args;
|
|
.sp
|
|
va_start(args, format);
|
|
/\(** print out name of function causing error \(**/
|
|
fprintf(stderr, "ERROR in %s: ", function_name);
|
|
/\(** print out remainder of message \(**/
|
|
vfprintf(stderr, format, args);
|
|
va_end(args);
|
|
}
|
|
.fi
|
|
.SH SEE ALSO
|
|
printf(3S), stdarg(5).
|
|
.SH DIAGNOSTICS
|
|
\f2vprintf\fP, \f2vfprintf\fP, \f2vsnprintf\fP, and \f2vsprintf\fP return the
|
|
number of characters
|
|
transmitted, or return \f2-1\fP if an error was encountered.
|
|
'\".so /pubs/tools/origin.att
|
|
.Ee
|