gpt4 book ai didi

c - 通过回车 C 拆分字符串

转载 作者:行者123 更新时间:2023-12-02 06:58:01 25 4
gpt4 key购买 nike

我在尝试通过 Web 代理的回车符拆分 HTTP 请求时遇到问题。请求似乎没有拆分。

这是一个示例请求:GET/pub/WWW/TheProject.html HTTP/1.1\r\n主机:www.w3.org\r\n

我的尝试是:

char* split_request;
split_request = strtok(request, "\r\n");

但它永远不会 split ?我不确定我错过了什么。当我使用 wget 或浏览器测试网络代理时,它似乎 split 了,但没有使用 telnet。

最佳答案

你是这样做的吗?

#include <stdio.h>
#include <string.h>

int main (void)
{
char str[] = "GET /pub/WWW/TheProject.html HTTP/1.1\r\nHost: www.w3.org\r\n";
char* pch = NULL;

pch = strtok(str, "\r\n");

while (pch != NULL)
{
printf("%s\n", pch);
pch = strtok(NULL, "\r\n");
}
return 0;
}

输出:

GET /pub/WWW/TheProject.html HTTP/1.1   
Host: www.w3.org

关于c - 通过回车 C 拆分字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27098332/

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