This documentation is archived and is not being maintained.

_vsnprintf, _vsnwprintf

Write formatted output using a pointer to a list of arguments.

int _vsnprintf(
   char *buffer,
   size_t count,
   const char *format,
   va_list argptr 
int _vsnwprintf(
   wchar_t *buffer,
   size_t count,
   const wchar_t *format,
   va_list argptr 


Storage location for output.
Maximum number of characters to write.
Format specification.
Pointer to list of arguments.

Return Value

_vsnprintf and _vsnwprintf return the number of characters written, not including the terminating null character, or a negative value if an output error occurs. If the number of characters to write exceeds count, then count characters are written and –1 is returned.


Each of these functions takes a pointer to an argument list, then formats and writes the given data to the memory pointed to by buffer.

Security Note   Ensure that format is not a user-defined string. For more information, see Avoiding Buffer Overruns.

Generic-Text Routine Mappings

TCHAR.H routine _UNICODE & _MBCS not defined _MBCS defined _UNICODE defined
_vsntprintf _vsnprintf _vsnprintf _vsnwprintf


Routine Required header Optional headers Compatibility
_vsnprintf <stdio.h> and <stdarg.h> <varargs.h>* Win 98, Win Me, Win NT, Win 2000, Win XP
_vsnwprintf <stdio.h> or <wchar.h>, and <stdarg.h> <varargs.h>* Win 98, Win Me, Win NT, Win 2000, Win XP

* Required for UNIX V compatibility.

For additional compatibility information, see Compatibility in the Introduction.


All versions of the C run-time libraries.


// crt_vsnprintf.c
#include <stdarg.h>
#include <wtypes.h>

void VarArg(LPCSTR formatstring, ...) 
   int nSize = 0;
   char buff[255];
   va_list args;
   va_start(args, formatstring);

   nSize = _vsnprintf( buff, sizeof(buff), formatstring, args);

int main() {
   VarArg("%s World", "Hello");

See Also

   Stream I/O Routines | vprintf Functions Overview | fprintf | printf | sprintf | va_arg | Run-Time Routines and .NET Framework Equivalents