Name
swprintf
Synopsis
Stores formatted output in a wide-character string buffer
#include <wchar.h> intswprintf
( wchar_t * restrictdest
, size_tn
, const wchar_t * restrictformat
, ... );
The swprintf()
function is
similar to snprintf()
, except
that its format string argument and its output are strings of wide
characters.
Example
const wchar_t *dollar_as_wstr( long amount)
// Converts a number of cents into a wide string showing dollars and cents.
// For example, converts (long)-123456 into the wide string L"-$1234.56"
{
static wchar_t buffer[16]
wchar_t sign[2] = L"";
if ( amount < 0L)
amount = -amount, sign[0] = '-';
ldiv_t dollars_cents = ldiv( amount, 100);swprintf
( buffer, sizeof(buffer),
L"%ls$%ld.%2ld", sign, dollars_cents.quot, dollars_cents.rem );
return buffer;
}
See Also
wprintf()
and fwprintf()
, declared
in stdio.h and wchar.h; and vwprintf()
, vfwprintf()
, and vswprintf()
, declared in stdarg.h; printf()
, fprintf()
, sprintf()
, snprintf()
, declared
in stdio.h; vprintf()
, vfprintf()
, vsprintf()
, vsnprintf()
, declared in stdarg.h; the wscanf()
input
functions. Argument conversion in the printf()
family of
functions is described in detail under printf()
in this
chapter.
Get C in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.