#include <string.h> void *memmove(void *to, const void *from, size_t n);
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.
memmove
returns a pointer to the to
area.
memmove
is size_t
. If a negative number
is passed, massive overlaying of memory may occur.
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); }
memcpy
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.