How do I concatenate const/literal strings in C?

前端 未结 17 1497
醉梦人生
醉梦人生 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

    Folks, use strncpy(), strncat(), or snprintf().
    Exceeding your buffer space will trash whatever else follows in memory!
    (And remember to allow space for the trailing null '\0' character!)

提交回复
热议问题