How to split a sprintf string into multiple lines in C?

0

I have a string in sprintf and I would like to split it into multiple lines as it gets big and the code gets messed up.

sprintf(srt,"GET %s HTTP/1.1\r\nAccept: text/javascript\r\nUser-Agent: Custom HTTP User Agent\r\nHost: %s\r\nConnection: Close\r\n\r\n, url, host);

How could I split this into multiple rows by making the code more organized? For example:

GET %s HTTP/1.1\r\n
Accept: text/javascript\r\n
User-Agent: Custom HTTP User Agent\r\n
Host: %s\r\n
Connection: Close\r\n
\r\n
    
asked by anonymous 04.09.2016 / 05:40

1 answer

2

In C, adjacent and adjacent strings are concatenated. So you can naturally split your string into several parts, each part in a line, but each part needs to have its own quotes.

So:

"GET %s HTTP/1.1\r\n"
"Accept: text/javascript\r\n"
"User-Agent: Custom HTTP User Agent\r\n"
"Host: %s\r\n"
"Connection: Close\r\n"
"\r\n"
    
04.09.2016 / 05:51