#include <stdio.h>
#include <windows.h>
void My_strcpy(char *p, const char *str)
{
char *pt = p;//使p的指向保持不变
if (p == NULL && str == NULL){//防止指针为空
return;
}
while (*pt++ = *str++)//一一拷贝
{
;
}
}
int main()
{
char *str = "hello world";
char p[20] = { 0 };
My_strcpy(p, str);//自己定义的strcpy
printf("%s\n", p);
system("pause");
return 0;
}