its a c library function which is used to tokenize a given string based on the token character provided.
its prototype is char *strtok(char *str, const char*tok).
char a[] = "This is-queryhome.com-QA-website";
char *tok = strtok(a, '-');
while(tok!=NULL)
{
printf("%s\n" tok);
tok = strtok(NULL, '-');
}
Output:
This is
queryhome.com
QA
website
Basically strtok() function maintains a local static reference, which points to the next token in the string, when we pass a null to strtok() its uses that internal reference. This is the reason strtok is neither re-entrant nor thread safe. as you pass the new reference to strtok() that old internal reference gets overwrite.