Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>#include &lt;stdlib.h&gt; // did you included this? void* MYmemmove (void* destination, const void* source, size_t num) { char *Source = source, *Destination = destination; char *Middle = malloc( sizeof(char) * num ); // midbuf for (int i = 0; i &lt; num ; i++) { Middle[i] = Destination[i]; // Copy source to midbuf } for (int i = 0; i &lt; num ; i++) { Destination[i] = Middle[i]; // Copy midbuf to destination } free(Middle); // free memory allocated previously with malloc return destination; } </code></pre> <p>Acces violation could occur because you didn't included libraries needed for malloc (standard c doesn't throw errors in your face if you forgot a function definition). You don't need to mark pointers as NULL since there's no garbage collection in C (pointers are just that - pointers. Addresses to a point in memory, not memory themselves).</p> <p>think about pointers like</p> <p>addres of pointer 0x1243 0x4221 Destination -> {some kind of data}</p> <p>Destination = 0x1243 *Destination = whatever value is currently at addres 0x4221</p> <p>You can't also index void pointers. You must first cast them to some type, so the compiler knows how much offset they need.</p> <p>Destination[x] = *(Destination+x)</p> <p>a char is 1 byte, so char pointer will really get moved by x bytes, but an int is 4 bytes, and an int pointer will get moved by 4*x bytes. Don't worry too much if it sounds technical, it'll be important when you'll get to something really low level ;)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload