function
<cwchar>

swscanf

int swscanf (const wchar_t* ws, const wchar_t* format, ...);
Read formatted data from string
Reads data from the wide string ws and stores them according to parameter format into the locations given by the additional arguments, as if wscanf was used, but reading from ws instead of the standard input (stdin).

The additional arguments should point to already allocated objects of the type specified by their corresponding format specifier within the format string.

This is the wide character equivalent of sscanf (<cstdio>).

Parameters

ws
C wide string that the function processes as its source to retrieve the data.
format
C wide string that contains a format string that follows the same specifications as format in scanf (see scanf for details).
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).
... (additional arguments)
Depending on the format string, the function may expect a sequence of additional arguments, each containing a pointer to allocated storage where the interpretation of the extracted characters is stored with the appropriate type.
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

On success, the function returns the number of items in the argument list successfully filled. This count can match the expected number of items or be less -even zero- in the case of a matching failure.
In the case of an input failure before any data could be successfully interpreted, EOF is returned.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* swscanf example */
#include <wchar.h>

int main ()
{
  wchar_t sentence [] = L"Michael is 10 years old";
  wchar_t str [20];
  int i;

  swscanf (sentence,L"%ls %*s %d",str,&i);
  wprintf (L"%ls -> %d\n",str,i);

  return 0;
}


Output:
Michael -> 10

See also