1 //子实现字符串的拼接
2 //2017.3.7
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 void strcat(char *p1, char *p2,int n1,int n2);
7 int main()
8 {
9 char str1[100] = "dfdfdfdf";
10 char str2[200] = "abcdfe";
11 char *p1 = str1;
12 char *p2 = str2;
13 int n1 = 0;
14 int n2 = 0;
15
16 strcat(p1, p2,n1,n2);
17 printf("拼接完成后的字符串为%s\n", str1);
18 system("pause");
19 return 1;
20 }
21
22 void strcat(char *p1, char *p2, int n1, int n2)
23 {
24 int i = 0;
25 while (*p1 != '\0')
26 {
27 n1++;
28 p1++;
29 }
30 //此时已经走到字符串str1的末尾
31 //遍历字符串str2
32 while (*p2 != '\0')
33 {
34 *(p1) = *(p2 );
35 p1++;
36 p2++;
37 }
38 *p1 = '\0';//记住这一句哈
39 }
![](https://images2015.cnblogs.com/blog/936260/201703/936260-20170310215743545-853363229.png)