How to concatenate strings in the C language?
In C language, the strcat() function can be used to concatenate strings. This function appends one string to the end of another string.
The sample code is as follows:
#include <stdio.h>
#include <string.h>
int main() {
char str1[50] = "Hello";
char str2[] = " World!";
strcat(str1, str2); // 将str2追加到str1的末尾
printf("合并后的字符串: %s\n", str1);
return 0;
}
The output results in:
Merged string: Hello World!
When using the strcat() function, make sure that the string being appended to is long enough to accommodate the appended string. Additionally, ensure that the str1 array is long enough to hold the final merged string.