Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

What is wprintf() in C?

Khizar Hayat Saani

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

wprintf() is a built-in function defined in the <wchar.h> header.

The following is the function prototype:

int wprintf (const wchar_t* format, ...);

Functionality

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.

How to use wprintf()

Code

#include <stdio.h>
#include <wchar.h>
#include <stddef.h>
int main(){
//Example 1: %ls -> long string
wchar_t str[] = L"Hello World!";
wprintf(L"Message: %ls\n", str);
//Example 2: %d -> int
wint_t num = 1133;
wprintf(L"The number is: %d\n", num);
//Example 3: %lc -> long char
wchar_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.

RELATED TAGS

c

CONTRIBUTOR

Khizar Hayat Saani
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring