Strtok usage, code not working [duplicate]
问题 This question already has answers here : strtok behavior (2 answers) Closed 6 years ago . I am trying to use strtok() . Following is the piece of code that I wrote. It does not work but prints ", '" infinitely. #include<stdio.h> #include<stdlib.h> #include<string.h> int main(){ char str[]="this, by the way, is a 'sample'"; char *tokens; tokens = strtok(str, ", '"); //printf("%s\n",tokens); //printf("%s\n", str); while(tokens!=NULL) { printf("%s\n", tokens); tokens = (NULL, ", '"); } return 0;