memmove -- Copy Characters

SYNOPSIS

 #include <string.h>

 void *memmove(void *to, const void *from, size_t n);
 

DESCRIPTION

memmove is identical to memcpy except that the copy is guaranteed to work correctly even if the to and from objects overlap. On completion of the call, the n bytes addressed by to are identical to the n bytes addressed by from before the call.

RETURN VALUE

memmove returns a pointer to the to area.

CAUTION

The third argument to memmove is size_t. If a negative number is passed, massive overlaying of memory may occur.

EXAMPLE

This example removes hyphens from a word by shifting text to the left to overlay any hyphens, using memmove:
  #include <string.h>
  #include <stdio.h>

  #define MAXLEN 100

  main()
  {
     char *word;
     size_t len;
     char *hyphen;
     char line[MAXLEN];

     puts("Enter a hyphenated word: ");
     word = gets(line);
     printf("noriginal word: %sn", word);
     len = strlen(word);
     for (;;) {
         hyphen = strchr(word, '-');
         if (!hyphen) break;
         memmove(hyphen, hyphen + 1, len - (hyphen - word));
            /* Remove hyphen from word. */
         --len;
     }
     printf("Unhyphenated word: %sn", word);
  }

 

RELATED FUNCTIONS

memcpy

SEE ALSO

String Utility Functions

Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.