* locale/programs/charmap-dir.c (charmap_aliases): Use %ms instead of
[glibc/pb-stable.git] / stdio-common / scanf14.c
blob387ceba4bb8500e2ea7257156f2614d43af4a290
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <wchar.h>
6 #define FAIL() \
7 do { \
8 result = 1; \
9 printf ("test at line %d failed\n", __LINE__); \
10 } while (0)
12 int
13 main (void)
15 wchar_t *lsp;
16 char *sp;
17 float f;
18 double d;
19 char c[8];
20 int result = 0;
22 if (sscanf (" 0.25s x", "%e%3c", &f, c) != 2)
23 FAIL ();
24 else if (f != 0.25 || memcmp (c, "s x", 3) != 0)
25 FAIL ();
26 if (sscanf (" 1.25s x", "%as%2c", &sp, c) != 2)
27 FAIL ();
28 else
30 if (strcmp (sp, "1.25s") != 0 || memcmp (c, " x", 2) != 0)
31 FAIL ();
32 memset (sp, 'x', sizeof "1.25s");
33 free (sp);
35 if (sscanf (" 2.25s x", "%las%2c", &d, c) != 2)
36 FAIL ();
37 else if (d != 2.25 || memcmp (c, " x", 2) != 0)
38 FAIL ();
39 if (sscanf (" 3.25S x", "%4aS%3c", &lsp, c) != 2)
40 FAIL ();
41 else
43 if (wcscmp (lsp, L"3.25") != 0 || memcmp (c, "S x", 3) != 0)
44 FAIL ();
45 memset (lsp, 'x', sizeof L"3.25");
46 free (lsp);
48 if (sscanf ("4.25[0-9.] x", "%a[0-9.]%8c", &sp, c) != 2)
49 FAIL ();
50 else
52 if (strcmp (sp, "4.25") != 0 || memcmp (c, "[0-9.] x", 8) != 0)
53 FAIL ();
54 memset (sp, 'x', sizeof "4.25");
55 free (sp);
57 if (sscanf ("5.25[0-9.] x", "%la[0-9.]%2c", &d, c) != 2)
58 FAIL ();
59 else if (d != 5.25 || memcmp (c, " x", 2) != 0)
60 FAIL ();
62 return result;