How do I concatenate const/literal strings in C?

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

    Strings can also be concatenated at compile time.

    #define SCHEMA "test"
    #define TABLE  "data"
    
    const char *table = SCHEMA "." TABLE ; // note no + or . or anything
    const char *qry =               // include comments in a string
        " SELECT * "                // get all fields
        " FROM " SCHEMA "." TABLE   /* the table */
        " WHERE x = 1 "             /* the filter */ 
                    ;
    

提交回复
热议问题