c - strtok。如何完成解析

标签 c strtok

在页面 https://msdn.microsoft.com/en-us/library/2c8d19sb.aspx在解析下一个字符串之前,我必须先完成对前一个字符串的解析:

Note

Each function uses a thread-local static variable for parsing the string into tokens. Therefore, multiple threads can simultaneously call these functions without undesirable effects. However, within a single thread, interleaving calls to one of these functions is highly likely to produce data corruption and inaccurate results. When parsing different strings, finish parsing one string before starting to parse the next. Also, be aware of the potential for danger when calling one of these functions from within a loop where another function is called. If the other function ends up using one of these functions, an interleaved sequence of calls will result, triggering data corruption.

这是什么意思?例如,我只需要第一个 token 。我必须继续调用 strtok(null, ) 来完成还是可以调用 strtok(string2, )

最佳答案

如果您使用的程序在不同线程之间没有连续的 strtok 调用,您可以根据需要获取第一个标记,然后在其他字符串上继续使用 strtok没有问题。

关于c - strtok。如何完成解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29515596/

相关文章:

python - Python 和 C 之间独立于操作系统的程序间通信

c - 单向链表 - C

c - 是否可以在 C 中重载运算符?

C strtok() 将字符串拆分为标记,但保持旧数据不变

C - 使用 strtok 用管道拆分字符串

c - 像 strtok() 这样的程序,用于两个分隔符

c - C 中字符串的指针

c - 具有低内存要求的渐近快速关联数组

c - 如何在C中将一个字符串拆分为2个字符串

c - 带分隔符的 strtok_r 标记