memcpyなどを使用して同様のことを実現することもできますが、本資料ではmemmoveを使用した記事です。
以下にmemmoveを使用したC言語サンプルソースを記します。
以下にmemmove関数の書式等を記します。
#include <string.h>
void *memmove(void *dest, const void *src, size_t n);
以下にmemmoveを使用したC言語サンプルソースを記します。 &ref(): File not found: "memmove.c" at page "メモリ/指定した文字数分コピーする・memmove"; (改行コードLF)
#include <stdio.h> #include <string.h> #define BUFSIZE 10 int main(void) { int i; char src1[] = { "0123456789" }; char src2[] = { "0123456789" }; char *dest ="dest"; memmove(&src1[0], &src1[5], 5); printf("%s\n", src1); memmove(src2, dest, strlen(dest)); printf("%s\n", src2); return 0; }
以下にコンパイルし実行した結果を記します。
$ gcc memmove.c -o memmove $ ./memmove 5678956789 dest456789
以上、memmoveのサンプルソースでした。
c-btm.html is not found or not readable.