strtok与空格分隔符

Nad*_*ern 2 c strtok

嘿,我试图在C中使用strtok函数,""作为分隔符,由于某种原因它不起作用.有人可以告诉我如何使用strtok解析如何使用空格作为分隔符提前感谢

Mic*_*urr 20

这里被盗(并稍加修改).

/* strtok example */
#include <stdio.h>
#include <string.h>

int main ()
{
  char str[] ="- This, a sample string.";
  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;
}
Run Code Online (Sandbox Code Playgroud)