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,
Try this:
char a[] = "A,B,C,D,E";
char * end_of_a = a + strlen(a); /* Memorise the end of s. */
char * separator = ",";
char * b = strtok(a, separator);
printf("a: %s\n", a);
printf("b: %s\n", b);
/* There might be some more tokenising here, assigning its result to b. */
if (NULL != b)
{
b = strtok(NULL, separator);
}
if (NULL != b)
{ /* Get reference to and print remainder: */
char * end_of_b = b + strlen(b);
if (end_of_b != end_of_a) /* Test whether there really needs to be something,
will say tokenising did not already reached the end of a,
which however is not the case for this example. */
{
char * remainder = end_of_b + 1;
printf("remainder: `%s`\n", remainder);
}
}