Replaced static variable by a library base member to
[aros:aros.git] / AROS / test / clib / strtok.c
1 #include <stdio.h>
2 #include <string.h>
3 #include "test.h"
4
5
6 int main(void)
7 {
8     {
9         // strtok()
10         char str[] = "This;is,a test"; // must be array
11         char del[] = ",;";
12         char *ptr;
13         int cnt = 0;
14
15         ptr = strtok(str, del);
16         while (ptr)
17         {
18             cnt++;
19             switch(cnt)
20             {
21                 case 1:
22                     TEST( strcmp(ptr, "This") == 0 );
23                     break;
24                 case 2:
25                     TEST( strcmp(ptr, "is") == 0 );
26                     break;
27                 case 3:
28                     TEST( strcmp(ptr, "a test") == 0 );
29                     break;
30                 default:
31                     TEST(0);
32                     break;
33             }
34             printf("%s\n", ptr);
35             ptr = strtok(NULL, del);
36         }
37     }
38
39     {
40         // strtok_r()
41         char str[] = "This;is,a test"; // must be array
42         char del[] = ",;";
43         char *ptr, *save;
44         int cnt = 0;
45
46         ptr = strtok_r(str, del, &save);
47         while (ptr)
48         {
49             cnt++;
50             switch(cnt)
51             {
52                 case 1:
53                     TEST( strcmp(ptr, "This") == 0 );
54                     break;
55                 case 2:
56                     TEST( strcmp(ptr, "is") == 0 );
57                     break;
58                 case 3:
59                     TEST( strcmp(ptr, "a test") == 0 );
60                     break;
61                 default:
62                     TEST(0);
63                     break;
64             }
65             printf("%s\n", ptr);
66             ptr = strtok_r(NULL, del, &save);
67         }
68     }
69     return OK;
70 }
71
72
73 void cleanup() 
74 {
75     /* Nothing to clean up */
76 }