Properly using sscanf

后端 未结 4 1144
星月不相逢
星月不相逢 2020-12-13 05:24

I am supposed to get an input line that can be in of any of the following formats:

  • There must be space between word 1 and word 2.
  • There must be a comm
4条回答
  •  感动是毒
    2020-12-13 06:01

    #include 
    #include 
    
    int main ()
    {
      char str[] ="word1 word2,word3";
      char* pch;
      printf ("Splitting string \"%s\" into tokens:\n",str);
    
      pch = strtok(str," ,");
      while (pch != NULL)
      {
        printf ("%s\n",pch);
        pch = strtok (NULL, " ,.-");
      }
      return 0;
    }
    

提交回复
热议问题