首页 > 代码库 > 【C语言】模拟实现memmove函数(考虑内存重叠)

【C语言】模拟实现memmove函数(考虑内存重叠)

//模拟实现memmove函数(考虑内存重叠)
#include <stdio.h>
#include <assert.h>
#include <string.h>
void * memmove(void * dst, const void * src, int count)
{
	void * ret = dst;
	assert(dst);
	assert(src);
	if (dst <= src || (char *)dst >= ((char *)src + count))   //正常情况不发生重叠,从低到高
	{
		while (count--) 
		{
			*(char *)dst = *(char *)src;
			dst = (char *)dst + 1;
			src = http://www.mamicode.com/(char *)src + 1;"hello!";
	char *q = "world";
	memmove(p, q,strlen(q)+1 );
	printf("%s\n", p);
	return 0;
}

【C语言】模拟实现memmove函数(考虑内存重叠)