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

Syntax

#include <stdio.h>

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

Description

vsprintf() is the same as the sprintf() function. In contrast to sprintf(),
vsprintf() allows for the output of arguments whose number and data type are not
known at the time of compilation.
vsprintf() is used in functions that can be passed a different format string as well as
different arguments for output from the caller. The format string format stands for the formal
parameter list of the function definition and a variable argument list ", ...".

vsprintf() processes an argument list arg with successive internal va_arg calls and
writes the arguments to the string s according to the format string format. The variable
argument list arg must be initialized before calling vsprintf() using the va_start macro.
The function has the following parameters:

char *s

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

const char *format

Format string like for printf() with ANSI functionality (see printf() for a
description).

The following difference exists with respect to white space characters (\n, \t, etc.):
vsprintf() enters the EBCDIC value of the control character in the resulting string. Only
when it is output to a text file will the control characters be converted to their appropriate
effect in accordance with the type of text file (see "White-space characters").

va_list arg

Pointer to the variable argument list that was initialized with va_start.

Return val.

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

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 upon returning.
The behavior is undefined for overlapping memory areas.

See also

vfprintf(), vprintf().