C语言中的库函数strcpy的模拟实现
strcpy的作用是复制字符串,将源字符串复制到目标字符串,返回值会返回目标字符串
头文件为<string.h>
char *strcpy(char *strDestination,const char *strSource);
下面我们来模拟实现一下strcpy的功能
//赋值表达式的值就是赋值操作完成后,左操作数的值。并且自增发生在条件判断之前
#include<stdio.h>
#include<assert.h>
char* my_strcpy(char* Destination,const char* Source)
{
assert(Destination && Source);
char* ret = Destination;
while (*Destination++ = *Source++);
return ret;
}
int main()
{
char arr[] = { "abcdeadjnauhdwifg" };
char aee[20] = { 0 };
printf("%s\n",my_strcpy(aee, arr));
return 0;
}

浙公网安备 33010602011771号