嘿,我试图在C中使用strtok函数,“”作为分隔符,由于某种原因它不起作用。 有人可以告诉我如何使用strtok解析如何使用空格作为分隔符 提前谢谢
答案 0 :(得分:20)
here被盗(并稍加修改)。
/* 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;
}
答案 1 :(得分:0)
使用标签“\ t”或同时使用“\ t”即。空格和制表符......看看它是否有效