#include<string.h>
#include<stdio.h>
#include<assert.h>
char* my_strcat(char* arr1, const char* arr2)
{
assert(arr1 && arr2 != NULL);
while (*arr1 != '\0') //找到arr1的\0
{
arr1++;
}
while (*arr1++ = *arr2++)
{
;
}
return arr1;
}
int main()
{
char arr1[30] = { "abc" };
char arr2[] = { "def" };
my_strcat(arr1,arr2);
printf("%s", arr1);
return 0;
}
总结:
1.源字符串必须以‘\0'结束
2.目标空间必须足够大,能够容纳所有字符串
3.目标空间必须可修改
标签:return,函数,++,strcat,char,arr2,arr1 From: https://blog.51cto.com/u_15835473/5826089