C string append

后端 未结 10 1314
野趣味
野趣味 2020-12-01 06:21

I want to append two strings. I used the following command:

new_str = strcat(str1, str2);

This command changes the value of str1

10条回答
  •  执念已碎
    2020-12-01 06:42

    You could use asprintf to concatenate both into a new string:

    char *new_str;
    asprintf(&new_str,"%s%s",str1,str2);
    

提交回复
热议问题