我想在另一个char数组中插入一个char数组
char TEST[100]="www.bing.com ";
char headers[256] = "GET /index HTTP/1.1\r\nHost: www.bing.com\r\nUser-Agent: Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0)\r\nReferer: \r\nConnection: Close\r\n\r\n";
如您所见,我想在第二个阵列中插入www.bing.com
char headers[256] = "GET /index HTTP/1.1\r\nHost: "+TEST[100]+"\r\nUser-Agent: Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0)\r\nReferer: \r\nConnection: Close\r\n\r\n";
这怎么可能?
答案 0 :(得分:4)
char buffer[512];
sprintf(buffer, "GET /index HTTP/1.1\r\nHost: %s\r\nUser-Agent: Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0)\r\nReferer: \r\nConnection: Close\r\n\r\n", TEST);
buffer
现在包含您想要的结果(请注意我在格式字符串中使用%s
如何在HTTP请求字符串中嵌入TEST
)