How do I concatenate const/literal strings in C?

前端 未结 17 1502
醉梦人生
醉梦人生 2020-11-21 23:45

I\'m working in C, and I have to concatenate a few things.

Right now I have this:

message = strcat(\"TEXT \", var);

message2 = strcat(strcat(\"TEXT          


        
17条回答
  •  礼貌的吻别
    2020-11-22 00:14

    You are trying to copy a string into an address that is statically allocated. You need to cat into a buffer.

    Specifically:

    ...snip...

    destination

    Pointer to the destination array, which should contain a C string, and be large enough to contain the concatenated resulting string.
    

    ...snip...

    http://www.cplusplus.com/reference/clibrary/cstring/strcat.html

    There's an example here as well.

提交回复
热议问题