How to concatenate strings in C language?
In C language, the strcat() function can be used to concatenate strings.
#include <stdio.h>
#include <string.h>
int main() {
char str1[100] = "Hello";
char str2[] = "World";
strcat(str1, str2);
printf("拼接后的字符串是:%s\n", str1);
return 0;
}
The above code will output: The concatenated string is: HelloWorld.
In the above code, two character arrays, str1 and str2, are first defined to store the strings to be concatenated. Then the strcat() function is used to concatenate str2 to the end of str1, and finally the concatenated result is printed.
It is important to note that the string before concatenation must have enough space to accommodate the concatenated string, otherwise it may lead to buffer overflow issues.