blob: 0ce78b6e4f058055a83b0fd92bc99c4ab8188695 (
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
 | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
	const char *buf = "hello world";
	char *ps = NULL, *pc = NULL;
	char s[6], c;
	/* Check that %[...]/%c work. */
	sscanf(buf, "%[a-z] %c", s, &c);
	/* Check that %m[...]/%mc work. */
	sscanf(buf, "%m[a-z] %mc", &ps, &pc);
	if (strcmp(ps, "hello") != 0 || *pc != 'w' ||
	    strcmp(s, "hello") != 0 || c != 'w')
		return 1;
	free(ps);
	free(pc);
	return 0;
}
 |