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]...);
buffer
size
buffer
, in characters. Size in chars for snprintf
or size in wchar_ts for the wide-character functions.
count
format
argument
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.
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) |
intime/rt/include/stdio.h intime/rt/include/wchar.h intime/rt/include/tchar.h |
stdio.h wchar.h tchar.h |
clib.lib |