c语言模拟实现strcpy函数

时间:2022-09-05 22:59:43

模拟实现strcpy

#include <stdio.h>

#include <windows.h>

#pragma warning(disable:4996)

#include <assert.h>

char* my_strcpy(char *dest, const char *src)//const规范使用者对函数的操作

{ char *ret = dest;

assert(dest != NULL);

assert(src != NULL);

while (*dest++ = *src++)//后置加加的妙用

{

;

}

return ret;

}

int main()

{

char arr1[10] = { 0 };

char arr2[10] = "hello!";

char *p = NULL;

p = my_strcpy(arr1,arr2); printf("%s\n",p);

system("pause");

return 0;

}