Back to index

glibc  2.9
tst_swscanf.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <string.h>
00003 #include <wchar.h>
00004 
00005 int
00006 main (int argc, char *argv[])
00007 {
00008   const wchar_t in[] = L"7 + 35 is 42";
00009   size_t n;
00010   int a, b, c;
00011   int result = 0;
00012   char buf1[20];
00013   wchar_t wbuf2[20];
00014   char buf3[20];
00015   char c4;
00016   wchar_t wc5;
00017 
00018   puts ("Test 1");
00019   a = b = c = 0;
00020   n = swscanf (in, L"%d + %d is %d", &a, &b, &c);
00021   if (n != 3 || a + b != c || c != 42)
00022     {
00023       printf ("*** FAILED, n = %Zu, a = %d, b = %d, c = %d\n", n, a, b, c);
00024       result = 1;
00025     }
00026 
00027   puts ("Test 2");
00028   n = swscanf (L"one two three !!", L"%s %S %s %c%C",
00029               buf1, wbuf2, buf3, &c4, &wc5);
00030   if (n != 5 || strcmp (buf1, "one") != 0 || wcscmp (wbuf2, L"two") != 0
00031       || strcmp (buf3, "three") != 0 || c4 != '!' || wc5 != L'!')
00032     {
00033       printf ("*** FAILED, n = %Zu, buf1 = \"%s\", wbuf2 = L\"%S\", buf3 = \"%s\", c4 = '%c', wc5 = L'%C'\n",
00034              n, buf1, wbuf2, buf3, c4, (wint_t) wc5);
00035       result = 1;
00036     }
00037 
00038   return result;
00039 }