1 /* Example of strtok adapted from:
2 https://en.cppreference.com/w/c/string/byte/strtok
4 "licensed under Creative Commons Attribution-Sharealike 3.0
5 Unported License (CC-BY-SA) and by the GNU Free Documentation License
6 (GFDL) (unversioned, with no invariant sections, front-cover texts, or
7 back-cover texts). That means that you can use this site in almost any way
8 you like, including mirroring, copying, translating, etc. All we would ask
9 is to provide link back to cppreference.com so that people know where to
10 get the most up-to-date content. In addition to that, any modified content
11 should be released under an equivalent license so that everyone could
12 benefit from the modified versions. " */
14 /* { dg-additional-options " -Wno-analyzer-too-complex -Wno-analyzer-symbol-too-complex" } */
16 #define __STDC_WANT_LIB_EXT1__ 0
22 char input
[] = "A bird came down the walk";
23 printf("Parsing the input string '%s'\n", input
);
24 char *token
= strtok(input
, " ");
27 token
= strtok(NULL
, " ");
30 printf("Contents of the input string now: '");
31 for(size_t n
= 0; n
< sizeof input
; ++n
)
32 input
[n
] ? putchar(input
[n
]) : fputs("\\0", stdout
);
35 #ifdef __STDC_LIB_EXT1__
36 char str
[] = "A bird came down the walk";
37 rsize_t strmax
= sizeof str
;
38 const char *delim
= " ";
40 printf("Parsing the input string '%s'\n", str
);
41 token
= strtok_s(str
, &strmax
, delim
, &next_token
);
44 token
= strtok_s(NULL
, &strmax
, delim
, &next_token
);
47 printf("Contents of the input string now: '");
48 for(size_t n
= 0; n
< sizeof str
; ++n
)
49 str
[n
] ? putchar(str
[n
]) : fputs("\\0", stdout
);