about summary refs log tree commit diff
path: root/stdio-common/tstdiomisc.c
blob: 0bd5515934ade8e2f9893a3f4047ea0d3119bdea (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>

void
t1 ()
{
  int n = -1;
  sscanf ("abc  ", "abc %n", &n);
  printf ("t1: count=%d\n", n);
}

void
t2 ()
{
  int n;
  long N;
  int retval;
#define SCAN(INPUT, FORMAT, VAR) \
  VAR = -1; \
  retval = sscanf (INPUT, FORMAT,  &VAR); \
  printf ("sscanf (\"%s\", \"%s\", &x) => %d, x = %ld\n", \
	  INPUT, FORMAT, retval, VAR);

  SCAN ("12345", "%ld", N);
  SCAN ("12345", "%llllld", N);
  SCAN ("12345", "%LLLLLd", N);
  SCAN ("test ", "%*s%n",  n);
  SCAN ("test ",   "%2*s%n",  n);
  SCAN ("12 ",   "%l2d",  n);
  SCAN ("12 ",   "%2ld",  N);
}

int
main ()
{
  t1 ();
  t2 ();

  fflush (stdout);
  return 0;
}