#include <string.h> char *strsep(char **restrict stringp, const char *restrict delim);
glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):
strsep():
Since glibc 2.19:
_DEFAULT_SOURCE
glibc 2.19 and earlier:
_BSD_SOURCE
| インターフェース | 属性 | 値 |
| strsep() | Thread safety | MT-Safe |
The strsep() function was introduced as a replacement for strtok(3), since the latter cannot handle empty fields.
$ ./a.out 'a/bbb///cc;xxx:yyy:' ':;' '/'
1: a/bbb///cc
--> a
--> bbb
-->
-->
--> cc
2: xxx
--> xxx
3: yyy
--> yyy
4:
-->
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int
main(int argc, char *argv[])
{
char *token, *subtoken;
if (argc != 4) {
fprintf(stderr, "Usage: %s string delim subdelim\n", argv[0]);
exit(EXIT_FAILURE);
}
for (unsigned int j = 1; (token = strsep(&argv[1], argv[2])); j++) {
printf("%u: %s\n", j, token);
while ((subtoken = strsep(&token, argv[3])))
printf("\t --> %s\n", subtoken);
}
exit(EXIT_SUCCESS);
}