Blame libio/tst_swscanf.c

Packit Service 82fcde
#include <stdio.h>
Packit Service 82fcde
#include <string.h>
Packit Service 82fcde
#include <wchar.h>
Packit Service 82fcde
Packit Service 82fcde
int
Packit Service 82fcde
main (int argc, char *argv[])
Packit Service 82fcde
{
Packit Service 82fcde
  const wchar_t in[] = L"7 + 35 is 42";
Packit Service 82fcde
  size_t n;
Packit Service 82fcde
  int a, b, c;
Packit Service 82fcde
  int result = 0;
Packit Service 82fcde
  char buf1[20];
Packit Service 82fcde
  wchar_t wbuf2[20];
Packit Service 82fcde
  char buf3[20];
Packit Service 82fcde
  char c4;
Packit Service 82fcde
  wchar_t wc5;
Packit Service 82fcde
Packit Service 82fcde
  puts ("Test 1");
Packit Service 82fcde
  a = b = c = 0;
Packit Service 82fcde
  n = swscanf (in, L"%d + %d is %d", &a, &b, &c);
Packit Service 82fcde
  if (n != 3 || a + b != c || c != 42)
Packit Service 82fcde
    {
Packit Service 82fcde
      printf ("*** FAILED, n = %Zu, a = %d, b = %d, c = %d\n", n, a, b, c);
Packit Service 82fcde
      result = 1;
Packit Service 82fcde
    }
Packit Service 82fcde
Packit Service 82fcde
  puts ("Test 2");
Packit Service 82fcde
  n = swscanf (L"one two three !!", L"%s %S %s %c%C",
Packit Service 82fcde
	       buf1, wbuf2, buf3, &c4, &wc5;;
Packit Service 82fcde
  if (n != 5 || strcmp (buf1, "one") != 0 || wcscmp (wbuf2, L"two") != 0
Packit Service 82fcde
      || strcmp (buf3, "three") != 0 || c4 != '!' || wc5 != L'!')
Packit Service 82fcde
    {
Packit Service 82fcde
      printf ("*** FAILED, n = %Zu, buf1 = \"%s\", wbuf2 = L\"%S\", buf3 = \"%s\", c4 = '%c', wc5 = L'%C'\n",
Packit Service 82fcde
	      n, buf1, wbuf2, buf3, c4, (wint_t) wc5);
Packit Service 82fcde
      result = 1;
Packit Service 82fcde
    }
Packit Service 82fcde
Packit Service 82fcde
  return result;
Packit Service 82fcde
}