我找到了一个样例程序,它解释了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, " ,.-");
会返回一个新的标记。 我的意思是,我们正在使用 NULL
调用 strtok
。 对我来说这没有太多意义。
strtok_r()
函数... - vrdhn