INtime SDK Help
_snprintf, _snprintf_s, _snwprintf, _snwprintf_s

 Prints formatted data to a string while limiting the maximum number of characters to produce.

#include <stdio.h>

int _snprintf(char *buffer, size_t size, const char *format[, argument]...);
int _snprintf_s(char *buffer, rsize_t size, size_t count, const char *format[, argument]...);
#include <wchar.h>

int _snwprintf(wchar_t *buffer, size_t size, const wchar_t *format[, argument]...);
int _snwprintf_s(wchar_t *buffer, rsize_t size, size_t count, const wchar_t *format[, argument]...);


Output buffer.
The size of the storage location at buffer, in characters. Size in chars for snprintf or size in wchar_ts for the wide-character functions.
Maximum number of characters to write (not including the terminating null), or _TRUNCATE.
Formatted string consisting of ordinary characters, escape sequences, and, if arguments appear, format specifications. The format and optional arguments have the same form and function as printf.
Optional arguments.

Return Values

These functions return the number of characters stored in buffer, not counting the terminating null character.

If the storage required to store the data and a terminating null exceeds size, the functions _snprintf_s and _snwprintf_s set buffer to an empty string, set errno to ERANGE, and return -1.

If buffer or format is a NULL pointer, or if count is less than or equal to zero, the invalid parameter handler is invoked. If execution is allowed to continue, these functions set errno to EINVAL and return -1.


The _snprintf_s function formats and stores count or fewer characters in buffer and appends a terminating null. Each argument (if any) is converted and output according to the corresponding format specification in format. The formatting is consistent with the printf family of functions. If copying occurs between strings that overlap, the behavior is undefined.

If count is _TRUNCATE, then _snprintf_s writes as much of the string as will fit in buffer while leaving room for a terminating null. If the entire string (with terminating null) fits in buffer, then _snprintf_s returns the number of characters written (not including the terminating null); otherwise, _snprintf_s returns -1 to indicate that truncation occurred.

Generic Text Routines

tchar.h routine _UNICODE not defined _UNICODE defined
_sntprintf _snprintf _snwprintf
_sntprintf_s _snprintf_s _snwprintf_s


Versions Defined in Include Link to
INtime 3.0
INtime 6.0 (for wide-character and generic text calls)
See Also