Why is strtok changing its input like this?

后端 未结 3 1512
遇见更好的自我
遇见更好的自我 2020-11-30 04:57

Ok, so I understand that strtok modifies its input argument, but in this case, it\'s collapsing down the input string into only the first token. Why is this happening, and w

3条回答
  •  野性不改
    2020-11-30 05:49

    You should printout the token that you receive from strtok and not worry about the input array because NULLs will be inserted by strtok. You need repeated calls to get all of the tokens:

    #include 
    #include 
    #include 
    
    int main(int argc, char* argv[]) {
      char input[]="this is a test of the tokenizor seven";
      char * temp;
      temp=strtok(input," ");
      while( temp != NULL ) {
        printf("temp is \"%s\"\n", temp );
        temp = strtok( NULL, " ");
      }
    }
    

提交回复
热议问题