wprintf() is a built-in function defined in the <wchar.h> header.
The following is the function prototype:
int wprintf (const wchar_t* format, ...);
wprintf() is used to write the wide-character string (pointed to by format) to the standard-output (stdout).
The functionality of wprintf() is similar to the printf() function defined in the <stdio.h> header.
Relevant placeholders replace the format specifiers within the format string. These placeholders are passed as additional arguments represented by ... in the prototype.
#include <stdio.h>#include <wchar.h>#include <stddef.h>int main(){//Example 1: %ls -> long stringwchar_t str[] = L"Hello World!";wprintf(L"Message: %ls\n", str);//Example 2: %d -> intwint_t num = 1133;wprintf(L"The number is: %d\n", num);//Example 3: %lc -> long charwchar_t myChar = 'K';wprintf(L"The char is: %lc", myChar);return 0;}
In the above example, we use wprintf() to print wide character strings.
We use three different format specifiers depending on the type of additional argument passed to wprintf().
To declare a wide-character string, we prefix the string with the letter
L.
Free Resources