December 2005
Beginner to intermediate
618 pages
20h 19m
English
swprintf
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.
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;
}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.
Read now
Unlock full access