Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

vsprintf - Formatted output to a string

&pagelevel(4)&pagelevel

Definition

#include <stdarg.h>
#include <stdio.h>

int vsprintf(char *s, const char *format, va_list arg);

vsprintf is similar to the sprintf function. In contrast to sprintf, vsprintf enables
arguments to be output whose number and data types are not known at compilation time.
vsprintf is used within functions to which the caller can pass a different format string and
different arguments for output each time. The formal parameter list of the function definition
provides for a format string format and a variable argument list ", ..." for this purpose.

vsprintf successively steps through an argument list arg using internal va_arg calls and
writes the arguments according to format string format to string s. The variable argument list
arg must be initialized with the va_start macro before vsprintf is called.

Parameters  char *s

Pointer to the result string. vsprintf terminates the string with the null byte (\0).

const char *format

Format string as described under printf with ANSI functionality (cf. printf).

The only difference is the way in which the control characters for white space (\n, \t, etc.)
are handled: vsprintf enters the value of the control character into the result string. It
is only during output to text files that the control characters are converted to their
appropriate effect depending on the type of text file (see section “White space” (Basic terms)).

va_list arg

Pointer to the variable argument list initialized with va_start.

Return val.

Number of characters stored in s. The terminating null byte (\0) generated by vsprintf is

not included in this total.

Notes

vsprintf always starts with the first argument in the variable argument list. It is possible
to start output from any particular argument by issuing the appropriate number of va_arg
calls before calling the vsprintf function. Each va_arg call advances the position in the
argument list by one argument.

vsprintf does not call the va_end macro. Since vsprintf uses the va_arg macro, the
value of arg is undefined on return.

The behavior is undefined if memory areas overlap.

Example

See also

See under vfprintf

vfprintf, vprintf , vsnprintf