I think it's the very first strtok call that's failing. It's been a while since I've written C and I'm at a loss. Thanks very much.
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
char *str = "one|two|three";
char *tok = strtok(str, "|");
while (tok != NULL) {
printf("%s\n", tok);
tok = strtok(NULL, "|");
}
return 0;
}
strsep
is functionally equivalent tostrtok
but with a superior calling convention. It's a nonstandard BSDism, but everyone except Windows has it, and it's a shame that C99 inventedstrtok_r
instead of picking it up. – Kirststrsep
has significantly different semantics in the presence of multiple consecutive delimiter characters. – Boltrope