1#include <stdio.h>
2#include <string.h>
3#include <wchar.h>
4
5
6int
7main(int argc, char *argv[])
8{
9	const wchar_t in[] =L"7 + 35 is 42" ;
10	size_t n;
11	int a, b, c;
12	int result = 0;
13	char buf1[20];
14	wchar_t wbuf2[20];
15	char buf3[20];
16	char c4;
17	wchar_t wc5;
18
19	puts ("Test 1");
20	a = b = c = 0;
21	n = swscanf (in, L"%d + %d is %d", &a, &b, &c);
22	if (n != 3 || a + b != c || c != 42) {
23		printf ("*** FAILED, n = %Zu, a = %d, b = %d, c = %d\n", n, a, b, c);
24		result = 1;
25	}
26
27	puts ("Test 2");
28	n = swscanf (L"one two three !!", L"%s %S %s %c%C",
29		buf1, wbuf2, buf3, &c4, &wc5);
30	if (n != 5 || strcmp (buf1, "one") != 0 || wcscmp (wbuf2, L"two") != 0
31		|| strcmp (buf3, "three") != 0 || c4 != '!' || wc5 != L'!') {
32		printf ("*** FAILED, n = %Zu, buf1 = \"%s\", wbuf2 = L\"%S\", buf3 = \"%s\", c4 = '%c', wc5 = L'%C'\n",
33			n, buf1, wbuf2, buf3, c4, (wint_t) wc5);
34      result = 1;
35    }
36
37	return result;
38}
39