Reputation: 14950
I would like to insert a char array in another char array
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";
As you can see, I would like to insert the www.bing.com in the 2nd array
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";
How is this possible?
Upvotes: 0
Views: 164
Reputation: 5412
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
now contains the result you want (note how I used %s
in the format string to embed TEST
inside the HTTP Request string)
Upvotes: 4