diff options
author | haturatu <taro@eyes4you.org> | 2024-12-12 19:39:56 +0900 |
---|---|---|
committer | haturatu <taro@eyes4you.org> | 2024-12-12 19:39:56 +0900 |
commit | 9ed0c06de64b7bd6f5390c4f5972ac0578c0f858 (patch) | |
tree | 6ad61ca8f1f5a4375620313bf863a95d232d6a66 | |
parent | 1d810e685c5d97426bf6fe07d879a8cddd7b5743 (diff) |
wip
-rwxr-xr-x | a | bin | 0 -> 15656 bytes | |||
-rw-r--r-- | memchr.c | 16 | ||||
-rw-r--r-- | memcmp.c | 15 | ||||
-rw-r--r-- | memcpy.c | 15 | ||||
-rw-r--r-- | memmove.c | 19 |
5 files changed, 65 insertions, 0 deletions
Binary files differ diff --git a/memchr.c b/memchr.c new file mode 100644 index 0000000..ec05235 --- /dev/null +++ b/memchr.c @@ -0,0 +1,16 @@ +#include <stdio.h> +#include <string.h> + +int main() +{ + char *ptr; + char str[] = "test"; + + ptr = memchr(str ,'s', strlen(str)); + if (ptr != NULL) { + printf("文字「s」の場所: %ld\n", ptr - str + 1); + } else { + printf("文字「s」は見つかりませんでした。\n"); + } + // => 文字「s」の場所: 3 +} diff --git a/memcmp.c b/memcmp.c new file mode 100644 index 0000000..e9ad5b7 --- /dev/null +++ b/memcmp.c @@ -0,0 +1,15 @@ +#include <stdio.h> +#include <string.h> + +int main() +{ + char str1[5] = "test"; + char str2[5] = {'t', 'e', 's', 't', '\0'}; + + if (memcmp(str1, str2, 5*sizeof(char)) == 0) { + printf("str1とstr2は同じです。\n"); + } else { + printf("str1とstr2は異なります。\n"); + } + // => str1とstr2は同じです。 +} diff --git a/memcpy.c b/memcpy.c new file mode 100644 index 0000000..2131ef6 --- /dev/null +++ b/memcpy.c @@ -0,0 +1,15 @@ +#include <stdio.h> +#include <string.h> + +int main() +{ + char str1[10] = "Hi johnny"; + char str2[10] = {0}; + if (memcpy(str2, str1, strlen(str1))) { + printf("コピー元: %s\nコピー先: %s\n", str1, str2); + // コピー元: Hi johnny + // コピー先: Hi johnny + } else { + fprintf(stderr, "Error while coping str1 into str2.\n"); + } +} diff --git a/memmove.c b/memmove.c new file mode 100644 index 0000000..f766ad0 --- /dev/null +++ b/memmove.c @@ -0,0 +1,19 @@ +#include <stdio.h> +#include <string.h> + +int main() +{ + char str[20] = "abc,def"; + + printf("memmove()実行前\n"); + printf("%s\n", str); + /// => abc,def + + if (memmove(str+4, str, strlen(str))) { + printf("memmove()実行後\n"); + printf("%s\n", str); + // => abc,abc,def + } else { + fprintf(stderr, "エラー発生\n"); + } +} |