【发布时间】:2014-02-01 13:13:18
【问题描述】:
我找到了解释strtok函数的示例程序:
#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;
}
但是,我不明白这是如何工作的。
pch = strtok (NULL, " ,.-"); 怎么可能返回一个新的令牌。我的意思是,我们打电话给strtok和NULL。这对我来说没有多大意义。
【问题讨论】:
-
"我找到了这个解释 strtok 函数的示例程序它不是解释的例子,而是文档,所以你可能想在这里阅读:man7.org/linux/man-pages/man3/strtok.3.html跨度>
-
这对任何人都没有意义......所以
strtok_r()被创建...... -
OT:顺便说一句,我是
int main (void)。