gpt4 book ai didi

c - C 中的 strtok 函数如何工作?

转载 作者:太空狗 更新时间:2023-10-29 16:27:32 25 4
gpt4 key购买 nike

<分区>

我找到了解释 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。这对我来说意义不大。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com