How to use strtok()

前端 未结 2 1714
再見小時候
再見小時候 2020-12-06 20:41

I\'m writing a C program to study the usage of function strtok(). Here is my code:

#include 
#include 

main() {
         


        
2条回答
  •  猫巷女王i
    2020-12-06 21:01

    you should write sth like this:

    #include
    #include
    
    int main();
    {
    char string[] = "ls &"; //you should not write 100, cuz you waste memory
    char *pointer;
    
    pointer = strtok(string, " "); //skip only spaces
    while(pointer != NULL)
       {
          printf("%s\n", pointer);
          pointer = strtok(string, " ");
       }
    return 0;
    }
    

提交回复
热议问题