strcpy函数介绍
c语言代码实现
#include<stdio.h>
#include<assert.h>
char* my_strcpy(char* dest, const char* src)
{
assert(src != NULL);
assert(dest != NULL);
char* ret = dest;//存放目的字符串指针
while (*dest++ = *src++)//完成源字符串到目的字符串的拷贝,拷贝完\0之后循环结束
{
;
}
return ret;
}
int main()
{
char arr1[10] = "abc";//长度大于源字符串,防止溢出
char arr2[] = "defg";
char *p = my_strcpy(arr1, arr2);
printf("%s\n", p);
return 0;
}