1

嘿,我正在尝试使用 C 中的 strtok 函数,并以“”作为分隔符,但由于某种原因它不起作用。有人可以告诉我如何使用带有空格作为分隔符的 strtok 解析提前谢谢

4

2 回答 2

19

从这里被盗(并稍作修改)。

/* 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;
}
于 2010-11-11T23:29:30.313 回答
2

使用制表符“\t”或同时使用“\t”即。空格和制表符都...看看它是否有效

于 2011-11-14T00:56:59.627 回答