How do I concatenate const/literal strings in C?

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

    Best way to do it without having a limited buffer size is by using asprintf()

    char* concat(const char* str1, const char* str2)
    {
        char* result;
        asprintf(&result, "%s%s", str1, str2);
        return result;
    }
    

提交回复
热议问题