5.memcpy函数实现

#define _CRT_SECURE_NO_WARNINGS
#include
#include

typedef struct S
{
	char name[10];
	int age;
}s;

void* my_memcpy(void *dest, const void *src, size_t num)
{
	void* ret = dest;

	assert(dest != NULL);
	assert(src != NULL);

	while (num--)
	{
		*(char *)dest = *(char *)src;
		++(char*)dest;
		++(char*)src;
	}

	return ret;
}

int main()
{
	s a = { "小明", 10 };
	s b = { 0 };

	my_memcpy(&b , &a, sizeof(s));

	printf("%s %d\n", b.name, b.age);

	return;
}

 

你可能感兴趣的:(库函数,c语言)