c Programming/C Reference/stdio.h/wprintf

From Wikibooks, open books for an open world
Jump to: navigation, search

wprintf is a C standard library function as defined in wchar.h. It has function signature as

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

The wprintf() writes output to stdout, the standard output stream. It uses variable argument lists. This function and also functions like vprintf, vfprintf, vsprintf, vsnprintf, and vasprintf offer the ability for programmers to essentially create their own printf variants.


The wprintf function is found in C, in which writes the output to the stream under control of format strings. the format string specifies how subsequent arguments are converted for output.

wprintf is a wide character version of printf format. The format is a wide character string where wprintf and printf bahave similarly as they are opened in ANSI mode.


Following is the sample code for understanding of working of the wprintf.


int main(int argc,char *argv[])
      wchar_t *str = L"@TAJMAHAL@#$$$";
      wprintf(L"%ls\n", str);
      return EXIT_SUCCESS;

After running the code output will be as follows:



1. wprintf() is not portable function.
2. wprintf() cannot be mixed with printf().
3. wprintf cannot print the double values.

  for eg. 2^56 is the double value which cannot be printed using wprintf().Template:Prog-lang-stub