我们在使用c的时候,如果要实现字符串的拷贝,可能会用到strcpy函数。那么我们能否自己实现一下呢?
我们先来看一段代码
int _tmain(int argc, _TCHAR* argv[])
{
char * p1 = "abcde";
printf("*p1++ = %c \n", *p1++ ); //a ++在后 想当于 先将*p的值进行打印 然后*p+1
printf("*p1++ = %c \n", *p1++); //b
printf("*p1++ = %c \n", *p1++); //c
system("pause");
return 0;
}
我们借助指针来实现该函数
#include "stdafx.h"
#include <stdlib.h>
#include <string.h>
void myCopy(char *from, char* to)
{
//当*from为 '\0'的时候结束 每次执行语句后 *from *to自增 将指针加1
for ( ; *from != '\0'; *