0

my problem is next:

char str[25] = "exsample=string=to=split";
char a[2] = "=";
char* token;
token = strtok(str, a);

as you know that code saves first part "exsample" to string token

but how I can take next part of line? meaning string and all after it to split

Tanhua
  • 39
  • 1
  • 5

2 Answers2

0

From the documentation for strtok:

str
...
Alternativelly, a null pointer may be specified, in which case the function continues scanning where a previous successful call to the function ended.

In other words:

nextToken = strtok(NULL, a);
Michael
  • 57,169
  • 9
  • 80
  • 125
0

Just call token = strtok( NULL, a );

But you should consider using thread safe strtok_r() instead of strtok(). The man page for both functions includes a good example.

Ingo Leonhardt
  • 9,435
  • 2
  • 24
  • 33