How do I concatenate const/literal strings in C?

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

    Try something similar to this:

    #include 
    #include 
    
    int main(int argc, const char * argv[])
    {
      // Insert code here...
      char firstname[100], secondname[100];
      printf("Enter First Name: ");
      fgets(firstname, 100, stdin);
      printf("Enter Second Name: ");
      fgets(secondname,100,stdin);
      firstname[strlen(firstname)-1]= '\0';
      printf("fullname is %s %s", firstname, secondname);
    
      return 0;
    }
    

提交回复
热议问题