在C語言中,連接兩個字符串可以使用以下幾種方法:
char str1[20] = "Hello";
char str2[20] = "World";
strcat(str1, str2);
printf("%s", str1); // 輸出:HelloWorld
char str1[20] = "Hello";
char str2[20] = "World";
strncat(str1, str2, 3);
printf("%s", str1); // 輸出:HelloWor
char str[20];
sprintf(str, "%s%s", "Hello", "World");
printf("%s", str); // 輸出:HelloWorld
char str1[20] = "Hello";
char str2[20] = "World";
strncat(str1, str2, 3);
printf("%s", str1); // 輸出:HelloWor
這些是連接字符串的一些常見方法,開發者可以根據具體的需求選擇合適的方法來實現字符串的連接操作。