1995-12-06 00:14:32 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
1995-12-15 05:22:35 +00:00
|
|
|
int
|
1995-12-06 00:14:32 +00:00
|
|
|
t1 ()
|
|
|
|
{
|
|
|
|
int n = -1;
|
|
|
|
sscanf ("abc ", "abc %n", &n);
|
|
|
|
printf ("t1: count=%d\n", n);
|
1995-12-15 05:22:35 +00:00
|
|
|
|
|
|
|
return n != 5;
|
1995-12-06 00:14:32 +00:00
|
|
|
}
|
|
|
|
|
1995-12-15 05:22:35 +00:00
|
|
|
int
|
1995-12-06 00:14:32 +00:00
|
|
|
t2 ()
|
|
|
|
{
|
1995-12-15 05:22:35 +00:00
|
|
|
int result = 0;
|
1995-12-06 00:14:32 +00:00
|
|
|
int n;
|
|
|
|
long N;
|
|
|
|
int retval;
|
1995-12-15 05:22:35 +00:00
|
|
|
#define SCAN(INPUT, FORMAT, VAR, EXP_RES, EXP_VAL) \
|
1995-12-06 00:14:32 +00:00
|
|
|
VAR = -1; \
|
|
|
|
retval = sscanf (INPUT, FORMAT, &VAR); \
|
|
|
|
printf ("sscanf (\"%s\", \"%s\", &x) => %d, x = %ld\n", \
|
1995-12-15 05:22:35 +00:00
|
|
|
INPUT, FORMAT, retval, VAR); \
|
|
|
|
result |= retval != EXP_RES || VAR != EXP_VAL
|
|
|
|
|
|
|
|
SCAN ("12345", "%ld", N, 1, 12345);
|
|
|
|
SCAN ("12345", "%llllld", N, 0, -1);
|
|
|
|
SCAN ("12345", "%LLLLLd", N, 0, -1);
|
|
|
|
SCAN ("test ", "%*s%n", n, 0, 4);
|
|
|
|
SCAN ("test ", "%2*s%n", n, 0, -1);
|
|
|
|
SCAN ("12 ", "%l2d", n, 0, -1);
|
|
|
|
SCAN ("12 ", "%2ld", N, 1, 12);
|
|
|
|
|
|
|
|
return result;
|
1995-12-06 00:14:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main ()
|
|
|
|
{
|
1995-12-15 05:22:35 +00:00
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
result |= t1 ();
|
|
|
|
result |= t2 ();
|
|
|
|
|
|
|
|
result |= fflush (stdout) == EOF;
|
1995-12-06 00:14:32 +00:00
|
|
|
|
1995-12-15 05:22:35 +00:00
|
|
|
return result;
|
1995-12-06 00:14:32 +00:00
|
|
|
}
|