...
The first time strtok()
is called, the string is parsed into tokens, character delimiter, and address of the variable in which to return the result are passed as arguments. The strtok()
function parses the string up to the first instance of the delimiter character, replaces the character in place with a null NULL byte ('\0'
), and puts the address of the first character in the token to the passed-in variable. Subsequent calls to strtok()
begin parsing immediately after the most recently-placed null NULL character.
Because strtok()
modifies its argument, the string is subsequently unsafe and cannot be used in its original form. If you need to preserve the original string, copy it into a buffer and pass the address of the buffer to strtok()
instead of the original string.
...