HP C/iX Library Reference Manual (30026-90004)
394 Chapter5
HP C/iX Library Function Descriptions
vsprintf
vsprintf
Writes formatted data to a character string in memory using a variable argument list.
Syntax
#include <stdarg.h>
#include <stdio.h>
int vsprintf (char *
string
, const char *
format
,
va_list
arg
);
Parameters
string
A pointer to a buffer in memory where the data is to be written.
format
A pointer to a character string defining the format (or the character string
itself enclosed in double quotes).
arg
A variable argument list initialized by va_start (defined in the header
<stdarg.h>).
Return Values
≥0 The number of characters written.
<0 An error occurred.
Description
The
arg
parameter is a variable argument list containing variables or expressions
specifying the data to be written. The
arg
parameter must be initialized by the va_start
macro prior to a call to vsprintf().
This function returns the number of characters written to the string, not counting the
terminating null character, or a negative value (if an error occurs).
The
arg
parameter specifies conversion specifications and literal characters. Literal
characters are all characters that are not part of a conversion specification. Literal
characters are written to the buffer in memory exactly as they appear in the format.
Conversion Specifications
The following list shows the different components of a conversion specification in their
correct sequence:
1. A percent sign (%), which signals the beginning of a conversion specification; to output
a literal percent sign, you must type two percent signs (%%);
2. Zero or more flags, which affect the way a value is written (see below).
3. An optional decimal digit string which specifies a minimum field width.
4. An optional
precision
consisting of a dot (.) followed by a decimal digit string.