在页面 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/