strtok()
doesn't create a new string and return it; it returns a pointer to the token within the string you pass as argument to strtok()
. Therefore the original string gets affected.
strtok()
breaks the string means it replaces the delimiter
character with NULL and returns a pointer to the beginning of that token. Therefore after you run strtok()
the delim
characters will be replaced by NULL characters. You can read link1 link2.
As you can see in output of example in link2
, the output you are getting is as expected since the delim
character is replaced by strtok
.