My string is \"A,B,C,D,E\"
And the separator is \",\"
How can I get the remaining string after doing strtok() once, that is \"B,C,D,E\"
char a[] = \"A,B,
strtok
remembers the last string it worked with and where it ended. To get the next string, call it again with NULL
as first argument.
char a[] = "A,B,C,D,E";
const char *separator = ",";
char *b = strtok(a, separator);
while (b) {
printf("element: %s\n", b);
b = strtok(NULL, separator);
}
Note: This is not thread safe.