totn C Functions

C Language: vsprintf function
(Formatted String Write Using Variable Argument List)

In the C Programming Language, the vsprintf function writes formatted output to an object pointed to by s using arg as the variable argument list.

Syntax

The syntax for the vsprintf function in the C Language is:

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

Parameters or Arguments

s
An array where the output will be written.
format

Describes the output as well as provides a placeholder to insert the formatted string. Here are a few examples:

FormatExplanationExample
%dDisplay an integer10
%fDisplays a floating-point number in fixed decimal format10.500000
%.1fDisplays a floating-point number with 1 digit after the decimal10.5
%eDisplay a floating-point number in exponential (scientific notation)1.050000e+01
%gDisplay a floating-point number in either fixed decimal or exponential format depending on the size of the number (will not display trailing zeros)10.5
arg
A variable argument list.

Returns

The vsprintf function returns the number of characters stored in the array (not including the null character).

Required Header

In the C Language, the required header for the vsprintf function is:

#include <stdio.h>

Applies To

In the C Language, the vsprintf function can be used in the following versions:

  • ANSI/ISO 9899-1990

Similar Functions

Other C functions that are similar to the vsprintf function:

See Also

Other C functions that are noteworthy when dealing with the vsprintf function: