#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
int Mystrcpy(char* dest, const char* source)
{
assert(dest != NULL); //如果断言中表达式的值为真,断言通过,无事发生;
assert(source != NULL); //如果断言中表达式的值为假,断言失败,程序崩溃;
char* tmp = dest; //记录dest的初始值
while (*source != ‘\0’ )
{
*dest = *source;
++dest;
++source;
}
*dest = ‘\0’; //拷贝\0;
return tmp;
}
int main()
{
char dest[1024] = { 0 };
char source[] = “hello”;
Mystrcpy(dest, source);
printf("%s\n", dest);
system(“pause”);
return 0;
}
模拟实现strcpy
最新推荐文章于 2022-06-06 11:02:13 发布