Skip to main content
added 1 character in body
Source Link
chqrlie
  • 152.1k
  • 12
  • 145
  • 231

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*char newsrc*newsrc = (char*)src; char*char newdest*newdest = (char*)dest; while (i < n) { newdest[i] = newsrc[i]; i++; } newdest[i]='\0'; return newdest; } 

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; } 

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; } 
Fix trivial typos
Source Link
Jonathan Leffler
  • 759.4k
  • 145
  • 961
  • 1.3k

copy bytes wihoutwithout memcpy()

It's a home work. I want to implement memcpy(),. I was told memory area must not overlap. Actually I don't understand what doest that meanmeans, because this code works fine, but it there is a possibility of memory overlap, how. 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; } 

copy bytes wihout memcpy()

It's a home work. I want to implement memcpy(), I was told memory area must not overlap. Actually I don't understand what doest that mean, because this code works fine but it there is 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; } 

copy bytes without memcpy()

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; } 

It's a home work. I want to implement memcpy(), I was told memory area must not overlap. Actually I don't understand what doest that mean, because this code works fine but it there is 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; } 

It's a home work. I want to implement memcpy(), I was told memory area must not overlap. Actually I don't understand what doest that mean, because this code works fine but it there is 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; } 

It's a home work. I want to implement memcpy(), I was told memory area must not overlap. Actually I don't understand what doest that mean, because this code works fine but it there is 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; } 
Source Link
surjit
  • 348
  • 4
  • 16
Loading