It's a home work. I want to implement memcpy(). I was told memory area must not overlap. Actually I don't understand what that means, because this code works fine, but there is a possibility of memory overlap. How to prevent it?
void *mem_copy(void *dest, const void *src, unsigned int n) {
assert((src != NULL) && (n > 0));
int i = 0;
char *newsrc = (char*)src;
char *newdest = (char*)dest;
while (i < n) {
newdest[i] = newsrc[i];
i++;
}
newdest[i]='\0';
return newdest;
}