0

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?

2
  • You just did, didn't you? Commented Dec 6, 2014 at 2:12
  • @ScottHunter error -> invalid operands to binary + (have ‘char *’ and ‘char *’ Commented Dec 6, 2014 at 2:12

1 Answer 1

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 now contains the result you want (note how I used %s in the format string to embed TEST inside the HTTP Request string)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.