How do I concatenate two strings in C?

后端 未结 11 1029
春和景丽
春和景丽 2020-11-22 16:00

How do I add two strings?

I tried name = \"derp\" + \"herp\";, but I got an error:

Expression must have integral or enum type

11条回答
  •  心在旅途
    2020-11-22 17:01

    #include 
    #include 
    int main()
    {
       int a,l;
       char str[50],str1[50],str3[100];
       printf("\nEnter a string: ");
       scanf("%s",str);
       str3[0]='\0';
       printf("\nEnter the string which you want to concat with string one: ");
       scanf("%s",str1);
       strcat(str3,str);
       strcat(str3,str1);
       printf("\nThe string is %s\n",str3);
    }
    

提交回复
热议问题