]> git.sur5r.net Git - cc65/blob - testcode/lib/strqtok-test.c
Added an attribution.
[cc65] / testcode / lib / strqtok-test.c
1 /* strqtok-test.c
2 **
3 ** 2014-04-21, Paul Foerster
4 ** 2014-05-20, Greg King
5 **
6 ** This program tests that strqtok() correctly will parse strings
7 ** with quotation marks in them.  It should show this list of tokens
8 ** from the test strings:
9 **
10 ** >This<
11 ** >  is only    <
12 ** >a<
13 ** >short<
14 ** >quoting<
15 ** >test ,  honoring  blanks, commas<
16 ** >and<
17 ** >(4)<
18 ** >empty<
19 ** ><
20 ** ><
21 ** ><
22 ** ><
23 ** >strings,   EOT  <
24 **
25 ** It shouldn't show
26 **
27 ** >Bogus token<
28 */
29
30 #include <string.h>
31 #include <stdio.h>
32
33 void main(void)
34 {
35     /* b[] and s[] are declared as automatic, not static, variables
36     ** because strqtok() will change them.
37     ** They must be defined together; and, b[] must be defined first
38     ** (because they're copied onto the top-down stack).
39     */
40     char b[] = "Bogus token ";
41     char s[] = "  This ,  \"  is only    \"a   short   "
42         "quoting\"test ,  honoring  blanks"
43         ", commas\", and (4) empty \"\"\"\"\"\"\"\" \"strings,   EOT  ";
44     char *t = strqtok(s, " ,");
45
46     while (t != NULL) {
47         printf(">%s<\n", t);
48         t = strqtok(NULL, " ,");
49     }
50 }