模拟实现strcpy函数

时间:2022-04-09 01:14:35
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <assert.h>

char* my_strcpy(char* dest, const char* src)
{
	assert(dest && src != NULL);
	char* ret = dest;
	while (*src != '\0')
	{
		*dest = *src;
		dest++;
		src++;
	}
	*dest = *src;
	return ret;
}
int main()
{
	char arr1[] = "abcdef";
	char arr2[] = "qqqqqqqq";
    char* ret = my_strcpy(arr2, arr1);
	printf("%s\n", ret);
	return 0;
}