How can C language concatenate strings?
In the C language, you can use the strcat function to join strings. The prototype of the strcat function is:
char* strcat(char* destination, const char* source);
Destination is the target string, source is the string to be concatenated.
Below is an example code:
#include <stdio.h>
#include <string.h>
int main() {
char str1[100] = "Hello";
char str2[] = " World!";
strcat(str1, str2);
printf("连接后的字符串:%s\n", str1);
return 0;
}
In this example, str1 is the target string and str2 is the string to be concatenated. By calling the strcat function to concatenate str2 to str1, the final output is “Hello World!”.