Defining a string over multiple lines

后端 未结 3 494
鱼传尺愫
鱼传尺愫 2021-01-08 01:00

Please take the following:

char buffer[512];

memset(buffer, 0, sizeof(buffer));
sprintf(&buffer[0],\"This Is The Longest String In the World that in tex         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-08 01:48

    The newline continuation takes into account any whitespace within the code.

    You can take advantage of string literal concatenation for better readability:

    sprintf(buffer, "This Is The "
                    "Longest String In the World "
                    "that in text goes on and..");
    

    Using \ you'll need to begin the continuation of your string at column 0:

    sprintf(buffer, "This Is The \
    Longest String In the World \
    that in text goes on and..");
    

提交回复
热议问题