aboutsummaryrefslogtreecommitdiff
path: root/stdio-common/scanf9.c
blob: 7aca354d2a786f7612981023bb000ebba1a5d315 (plain)
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int
main (void)
{
  int matches;
  char str[10];

  str[0] = '\0';
  matches = -9;
  matches = sscanf ("x ]", "%[^] ]", str);
  printf ("Matches = %d, string str = \"%s\".\n", matches, str);
  printf ("str should be \"x\".\n");

  if (strcmp (str, "x"))
    abort ();

  str[0] = '\0';
  matches = -9;
  matches = sscanf (" ] x", "%[] ]", str);
  printf ("Matches = %d, string str = \"%s\".\n", matches, str);
  printf ("str should be \" ] \".\n");

  if (strcmp (str, " ] "))
    abort ();

  return 0;
}