Your Browser is not longer supported

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

{{viewport.spaceProperty.prod}}

vsnprintf - formatted output to a string

&pagelevel(4)&pagelevel

Syntax

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

int vsnprintf(char *s, size_t n, const char *format, va_list arg);

Description

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

int vsnprintf(char *s, size_t n, const char *format, va_list arg);

vsnprintf() formats data (characters, strings, numerical values)according to the specification in the format string and writes the data to the area to which s points.

vsnprintf() is similar to the vsprintf() function. In contrast to vsprintf(), vsnprintf() only outputs up to the buffer limit specified by the n parameter. This prevents buffer overrun. n must not exceed INT_MAX in size.

vsnprintf() outputs a maximum of n-1 characters and adds a NULL character (\0) at the end of the output. If n=0, nothing is output.

vsnprintf() exists, analogous to vsprintf() , as an ASCII, IEEE and ASCII/IEEE function (cf. sections “IEEE floating-point arithmetic” and “ASCII encoding”).

Parameters:
See fprintf().

Return val.

< 0

n > INT_MAX or output error.


= 0 .. n-1

It was possible to edit the output completely. The return value specifies the length of the output without the terminating NULL character.


> n

It was not possible to edit the output completely. The return value specifies the length of the output without the terminating NULL character which a complete output would require.