我正在尝试解析 HTTP 请求 header 。我需要拿起第一行:
获取/HTTP/1.1
然而,下面代码的输出是:
Method: (null)
Filename: (null)
Version: (null)
Client hostname: (null)
为什么?
代码:
char *token;
const char delimiter[2] = " ";
token = strtok(NULL, delimiter);
最佳答案
第一次调用 strtok 时,您需要提供要拆分的字符串作为第一个参数。对 strtok 的后续调用需要使用 NULL 作为第一个参数来获取后续的分隔字符串。
祝你好运。
关于c++ - C: strtok 值返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22234361/