Question: I have a function using strtok like this

```
void f1(char *name)
{
...
char *tmp;
tmp = strtok(names, " ,");
while(tmp)
{
...
tmp = strtok(NULL, " ,");
}
...
}

```

And i have a call f1("abc,def");

Problem is that in first call f1 gets abc,def
and in 2nd call gets just abc

I am confused.. Why is this so?

Answer: 
You say:

> 
> And i have a call f1("abc,def");
> 
> 
> 

That call is illegal - strtok modifies its first parameter and you are not allowed to modify string literals. What you get is undefined behaviour - anything could happen. You want:

```
char a[] = "abc,def";
f1( a );

```
Are you truly passing in a string literal?

```
f1("abc,def");

```

will pass a pointer to the string literal to the `strtok()` in `f1()` - since `strtok()` modifies the string, and a string literal can't be modified, so you'll get undefined behavior (though I would expect a crash or fault instead of unexpected results).