写一个函数,将两个字符串连接的c语言
时间: 2024-02-09 07:08:49 浏览: 131
下面是一个简单的函数,将两个字符串连接起来:
```c
#include <stdio.h>
#include <string.h>
void concat(char s1[], char s2[]) {
strcat(s1, s2);
}
int main() {
char str1[50] = "Hello ";
char str2[] = "World!";
concat(str1, str2);
printf("%s\n", str1); // Output: Hello World!
return 0;
}
```
该函数使用了 `strcat()` 函数,它可以将第二个字符串连接到第一个字符串的末尾。在主函数中,我们首先定义两个字符串,然后调用 `concat()` 函数将它们连接起来,并输出结果。
阅读全文
相关推荐














