Easiest way to shift a piece of malloc memory

c

Solution

Yes, use `memmove`:

char * buf = malloc(5);   // pointer arithmetic only on chars!

memmove(buf, buf + 1, 4);
memset(buf + 4, 0, 1);

Problem

I need to shift a piece of malloced memory down. Currently I am creating a temp piece of memory and then copying it over and them recopying it back with the shift ``` void * buf = malloc(5); void * temp = malloc(5); memcpy(temp, buf, 5); memset(buf, 0, 5); memcpy(buf, temp + 1, 4); ``` Is there a better way of doing this?

Original source