_vsnprintf, _vsnwprintf (Windows CE 5.0)

Send Feedback

Developing an Application > Microsoft C Run-time Library for Windows CE > Run-time Library Reference > vprintf Functions

These functions 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_tcount, constwchar_t *format, va_listargptr);

Parameters

  • buffer
    Storage location for output.
  • count
    Maximum number of characters to write.
  • format
    Format specification.
  • argptr
    Pointer to list of arguments.

Return Values

_vsnprintf returns the number of characters written, not including the terminating null character, or a negative value if an output error occurs. _vsnwprintf returns the number of bytes written, which is the typically the same as the number of characters unless the buffer contains multibyte characters.

For _vsnprintf, if the number of characters to write exceeds count, then count characters are written and –1 is returned.

If the string written to the buffer fits without the null terminator, the buffer is not null-terminated and the function returns success.

Remarks

These functions are supported by all versions of the C run-time libraries.

This function takes a pointer to an argument list, then formats and writes the given data to the memory pointed to by buffer.

**Security Note   **A buffer overrun is one of the most common sources of security risk, and can cause unpredictable results. To avoid this risk, ensure that format is not a user-defined string.

Safe String Functions

The following table shows generic-text routine mappings for this function.

TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_vsntprintf _vsnprintf _vsnprintf _vsnwprintf

For more information about TCHAR.H routines, see Generic Text Mappings.

Example

Description

#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);
}

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

Requirements

OS Versions: Windows CE 2.0 and later.

Header: stdarg.h, stdlib.h, wtypes.h.

Link Library: coredll.dll.

See Also

fprintf | printf | sprintf

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.