Posted By: user379888
Please explain to me the working of
strtok() function. The manual says it breaks the string into tokens. I am unable to understand from the manual what it actually does.
I added watches on
*pch to check its working when the first while loop occurred, the contents of
str were only “this”. How did the output shown below printed on the screen?
/* strtok example */
int main ()
char str ="- This, a sample string.";
char * pch;
printf ("Splitting string "%s"" into tokens:n""
strtok()divides the string into tokens. i.e. starting from any one of the delimiter to next one would be your one token. In your case, the starting token will be from "-" and end with next space " ". Then next token will start from " " and end with ",". Here you get "This" as output. Similarly the rest of the string gets split into tokens from space to space and finally ending the last token on "."
Answered By: Anonymous