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