If you are dealing with the wide characters then printf() and scanf() function cannot be used. There are different functions for input and output C wide string.
- wprintf() : The wprintf() function writes the wide string pointed to by format to stdout. The wide string format may contain format specifiers starting with % which are replaced by the values of variables that are passed to the wprintf() function as additional arguments.
int wprintf (const wchar_t* format, ...);
- format : A pointer to a null terminated wide string that is written to stdout. It consists of wide characters along with optional format specifiers starting with %. The format specifiers are replaced by the values of respective variables that follows format.
- … : Other additional arguments specifying the data to be printed. They occur in a sequence according to the format specifier.There should be at least as many of these arguments as the number of values specified in the format specifiers. Additional arguments are ignored by the function.
- Return Value :If successful, the wprintf() function returns number of characters written. On failure it returns a negative value. If successful, the wprintf() function returns number of characters written.
On failure it returns a negative value.
// C Program to show the wprintf () function.
#include <wchar.h> // Header file containing wprintf function
// Driver code
x = 5;
name = L
"x = %d \n"
"HELLO %ls \n"
x = 5 HELLO GEEKS
- wscanf() : The wscanf() function reads the data from stdin and stores the values into the respective variables. The additional arguments should point to already allocated objects of the type specified by their corresponding format specifier within the format string.
int wscanf (const wchar_t* format, ...);
- format : Pointer to a null-terminated character string that specifies how to read the input. It consists of format specifiers starting with %. Notice though, that all format specifiers have the same meaning as in scanf; therefore, %lc shall be used to read a wide character (and not %c), as well as %ls shall be used for wide strings (and not %s).
- … : Other additional arguments for receiving data. They occur in a sequence according to the format specifier.There should be at least as many of these arguments as the number of values stored by the format specifiers. Additional arguments are ignored by the function.
- Return Value : The wscanf() function returns the number of receiving arguments successfully assigned. We can count and match the expected number of items or be less due to a matching failure, a reading error is occured, or the reach of the end-of-file causes an error.
If failure occurs before the first receiving argument was assigned, EOF is returned.
// Program to show the wprintf () function.
#include <wchar.h> // Header file containing wscanf() function
"I am a %ls of CSE in %d year.\n"
, str, i);
I am a GEEK of CSE in 2 year.
- SDL library in C/C++ with examples
- snprintf() in C library
- wcstof function in C library
- C Library math.h functions
- isgraph() C library function
- difftime() C library function
- How to add "graphics.h" C/C++ library to gcc compiler in Linux
- Difference between Header file and Library
- Unordered Sets in C++ Standard Template Library
- How to print range of basic data types without any library function and constant in C?
- Inbuilt library functions for user Input | scanf, fscanf, sscanf, scanf_s, fscanf_s, sscanf_s
- time.h header file in C with Examples
- __builtin_inf() functions of GCC compiler
- Count substrings that contain all vowels | SET 2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.