11 sscanf ("abc ", "abc %n", &n
);
12 printf ("t1: count=%d\n", n
);
24 #define SCAN(INPUT, FORMAT, VAR, EXP_RES, EXP_VAL) \
26 retval = sscanf (INPUT, FORMAT, &VAR); \
27 printf ("sscanf (\"%s\", \"%s\", &x) => %d, x = %ld\n", \
28 INPUT, FORMAT, retval, (long int) VAR); \
29 result |= retval != EXP_RES || VAR != EXP_VAL
31 SCAN ("12345", "%ld", N
, 1, 12345);
32 SCAN ("12345", "%llllld", N
, 0, -1);
33 SCAN ("12345", "%LLLLLd", N
, 0, -1);
34 SCAN ("test ", "%*s%n", n
, 0, 4);
35 SCAN ("test ", "%2*s%n", n
, 0, -1);
36 SCAN ("12 ", "%l2d", n
, 0, -1);
37 SCAN ("12 ", "%2ld", N
, 1, 12);
41 retval
= sscanf ("1 1", "%d %Z", &n
, &N
);
42 printf ("sscanf (\"1 1\", \"%%d %%Z\", &n, &N) => %d, n = %d, N = %ld\n", \
44 result
|= retval
!= 1 || n
!= 1 || N
!= -1;
49 volatile double nanval
;
50 volatile double infval
;
51 volatile long double lnanval
;
52 volatile long double linfval
;
64 snprintf (buf
, sizeof buf
, "%a %A %e %E %f %F %g %G",
65 nanval
, nanval
, nanval
, nanval
, nanval
, nanval
, nanval
, nanval
);
66 result
= strcmp (buf
, "nan NAN nan NAN nan NAN nan NAN") != 0;
67 printf ("expected \"nan NAN nan NAN nan NAN nan NAN\", got \"%s\"\n", buf
);
69 snprintf (buf
, sizeof buf
, "%a %A %e %E %f %F %g %G",
70 -nanval
, -nanval
, -nanval
, -nanval
,
71 -nanval
, -nanval
, -nanval
, -nanval
);
72 result
= strcmp (buf
, "-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
73 printf ("expected \"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got \"%s\"\n",
76 infval
= DBL_MAX
* DBL_MAX
;
78 snprintf (buf
, sizeof buf
, "%a %A %e %E %f %F %g %G",
79 infval
, infval
, infval
, infval
, infval
, infval
, infval
, infval
);
80 result
|= strcmp (buf
, "inf INF inf INF inf INF inf INF") != 0;
81 printf ("expected \"inf INF inf INF inf INF inf INF\", got \"%s\"\n", buf
);
83 snprintf (buf
, sizeof buf
, "%a %A %e %E %f %F %g %G",
84 -infval
, -infval
, -infval
, -infval
,
85 -infval
, -infval
, -infval
, -infval
);
86 result
|= strcmp (buf
, "-inf -INF -inf -INF -inf -INF -inf -INF") != 0;
87 printf ("expected \"-inf -INF -inf -INF -inf -INF -inf -INF\", got \"%s\"\n",
90 swprintf (wbuf
, sizeof wbuf
/ sizeof (wbuf
[0]), L
"%a %A %e %E %f %F %g %G",
91 nanval
, nanval
, nanval
, nanval
, nanval
, nanval
, nanval
, nanval
);
92 result
|= wcscmp (wbuf
, L
"nan NAN nan NAN nan NAN nan NAN") != 0;
93 printf ("expected L\"nan NAN nan NAN nan NAN nan NAN\", got L\"%S\"\n", wbuf
);
95 swprintf (wbuf
, sizeof wbuf
/ sizeof (wbuf
[0]), L
"%a %A %e %E %f %F %g %G",
96 -nanval
, -nanval
, -nanval
, -nanval
,
97 -nanval
, -nanval
, -nanval
, -nanval
);
98 result
|= wcscmp (wbuf
, L
"-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
99 printf ("expected L\"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got L\"%S\"\n",
102 swprintf (wbuf
, sizeof wbuf
/ sizeof (wbuf
[0]), L
"%a %A %e %E %f %F %g %G",
103 infval
, infval
, infval
, infval
, infval
, infval
, infval
, infval
);
104 result
|= wcscmp (wbuf
, L
"inf INF inf INF inf INF inf INF") != 0;
105 printf ("expected L\"inf INF inf INF inf INF inf INF\", got L\"%S\"\n", wbuf
);
107 swprintf (wbuf
, sizeof wbuf
/ sizeof (wbuf
[0]), L
"%a %A %e %E %f %F %g %G",
108 -infval
, -infval
, -infval
, -infval
,
109 -infval
, -infval
, -infval
, -infval
);
110 result
|= wcscmp (wbuf
, L
"-inf -INF -inf -INF -inf -INF -inf -INF") != 0;
111 printf ("expected L\"-inf -INF -inf -INF -inf -INF -inf -INF\", got L\"%S\"\n",
116 snprintf (buf
, sizeof buf
, "%La %LA %Le %LE %Lf %LF %Lg %LG",
117 lnanval
, lnanval
, lnanval
, lnanval
,
118 lnanval
, lnanval
, lnanval
, lnanval
);
119 result
= strcmp (buf
, "nan NAN nan NAN nan NAN nan NAN") != 0;
120 printf ("expected \"nan NAN nan NAN nan NAN nan NAN\", got \"%s\"\n", buf
);
122 snprintf (buf
, sizeof buf
, "%La %LA %Le %LE %Lf %LF %Lg %LG",
123 -lnanval
, -lnanval
, -lnanval
, -lnanval
,
124 -lnanval
, -lnanval
, -lnanval
, -lnanval
);
125 result
= strcmp (buf
, "-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
126 printf ("expected \"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got \"%s\"\n",
129 linfval
= LDBL_MAX
* LDBL_MAX
;
131 snprintf (buf
, sizeof buf
, "%La %LA %Le %LE %Lf %LF %Lg %LG",
132 linfval
, linfval
, linfval
, linfval
,
133 linfval
, linfval
, linfval
, linfval
);
134 result
|= strcmp (buf
, "inf INF inf INF inf INF inf INF") != 0;
135 printf ("expected \"inf INF inf INF inf INF inf INF\", got \"%s\"\n", buf
);
137 snprintf (buf
, sizeof buf
, "%La %LA %Le %LE %Lf %LF %Lg %LG",
138 -linfval
, -linfval
, -linfval
, -linfval
,
139 -linfval
, -linfval
, -linfval
, -linfval
);
140 result
|= strcmp (buf
, "-inf -INF -inf -INF -inf -INF -inf -INF") != 0;
141 printf ("expected \"-inf -INF -inf -INF -inf -INF -inf -INF\", got \"%s\"\n",
144 swprintf (wbuf
, sizeof wbuf
/ sizeof (wbuf
[0]),
145 L
"%La %LA %Le %LE %Lf %LF %Lg %LG",
146 lnanval
, lnanval
, lnanval
, lnanval
,
147 lnanval
, lnanval
, lnanval
, lnanval
);
148 result
|= wcscmp (wbuf
, L
"nan NAN nan NAN nan NAN nan NAN") != 0;
149 printf ("expected L\"nan NAN nan NAN nan NAN nan NAN\", got L\"%S\"\n", wbuf
);
151 swprintf (wbuf
, sizeof wbuf
/ sizeof (wbuf
[0]),
152 L
"%La %LA %Le %LE %Lf %LF %Lg %LG",
153 -lnanval
, -lnanval
, -lnanval
, -lnanval
,
154 -lnanval
, -lnanval
, -lnanval
, -lnanval
);
155 result
|= wcscmp (wbuf
, L
"-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
156 printf ("expected L\"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got L\"%S\"\n",
159 swprintf (wbuf
, sizeof wbuf
/ sizeof (wbuf
[0]),
160 L
"%La %LA %Le %LE %Lf %LF %Lg %LG",
161 linfval
, linfval
, linfval
, linfval
,
162 linfval
, linfval
, linfval
, linfval
);
163 result
|= wcscmp (wbuf
, L
"inf INF inf INF inf INF inf INF") != 0;
164 printf ("expected L\"inf INF inf INF inf INF inf INF\", got L\"%S\"\n", wbuf
);
166 swprintf (wbuf
, sizeof wbuf
/ sizeof (wbuf
[0]),
167 L
"%La %LA %Le %LE %Lf %LF %Lg %LG",
168 -linfval
, -linfval
, -linfval
, -linfval
,
169 -linfval
, -linfval
, -linfval
, -linfval
);
170 result
|= wcscmp (wbuf
, L
"-inf -INF -inf -INF -inf -INF -inf -INF") != 0;
171 printf ("expected L\"-inf -INF -inf -INF -inf -INF -inf -INF\", got L\"%S\"\n",
178 main (int argc
, char *argv
[])
186 result
|= fflush (stdout
) == EOF
;