memmove() — Copy Bytes

Format

#include <string.h>
void *memmove(void *dest, const void *src, size_t count);

Language Level: ANSI

Threadsafe: Yes.

Description

The memmove() function copies count bytes of src to dest. This function allows copying between objects that might overlap as if src is first copied into a temporary array.

Return Value

The memmove() function returns a pointer to dest.

Example that uses memmove()

This example copies the word "shiny" from position target + 2 to position target + 8.

#include <string.h>
#include <stdio.h>
 
#define SIZE    21
 
char target[SIZE] = "a shiny white sphere";
 
int main( void )
{
  char * p = target + 8;  /* p points at the starting character
                          of the word we want to replace */
  char * source = target + 2; /* start of "shiny" */
 
  printf( "Before memmove, target is \"%s\"\n", target );
  memmove( p, source, 5 );
  printf( "After memmove, target becomes \"%s\"\n", target );
}
 
/*********************  Expected output:  ************************
 
Before memmove, target is "a shiny white sphere"
After memmove, target becomes "a shiny shiny sphere"
*/

Related Information



[ Top of Page | Previous Page | Next Page | Contents | Index ]