Format
#include <wchar.h>
int swscanf(const wchar_t *wcsbuffer, const wchar_t *format,
argument-list);
Language Level: ANSI 93
swscanf reads wide data from wcsbuffer into the
locations given by argument-list. swscanf is
equivalent to sscanf, except that it operates on wide characters.
Each argument in the argument-list must point to a variable with a type that corresponds to a type specifier in format. The format has the same form and function as the format string for scanf, with the following exceptions:
For a complete description of format specifiers, see scanf -- Read Data.
When swscanf reaches the end of the wide character string, it stops parsing and returns a value as indicated below (this behavior is the same as sscanf). If copying takes place between objects that overlap, the behavior is undefined.
Return Value
swscanf returns the number of input items that were
successfully converted and assigned. The value does not include
fields that were read but not assigned. If an input failure (such
as the end of the string) is encountered before any conversion,
swscanf returns EOF.
Example
This example uses swscanf to scan in wide characters,
and then prints them.
#include <wchar.h> #include <stdio.h>
int main(void)
{
wchar_t *tokenstring = L"xyz âAâBâCâDâE a 1234";
char string[20];
wchar_t wstring[20];
wchar_t wc;
int i;
int num;
num = swscanf(tokenstring, L"%s %ls %lc %d", string, wstring, &wc, &i);
printf("string = %s\n", string );
printf("wstring = %ls\n", wstring );
printf("wc = %lc\n", wc );
printf("i = %d\n", i );
printf("total number of fields scanned: %i\n", num);
return 0;
/*********************************************************************
The output should be similar to :
string = xyz
wstring = âAâBâCâDâE a
wc = 1
i = 234
total number of fields scanned: 4
*********************************************************************/
}
![]()
scanf -- Read Data
sscanf -- Read Data from Buffer
swprintf -- Format and Write Wide
Characters to Buffer
<wchar.h>