summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xabin0 -> 15656 bytes
-rw-r--r--memchr.c16
-rw-r--r--memcmp.c15
-rw-r--r--memcpy.c15
-rw-r--r--memmove.c19
5 files changed, 65 insertions, 0 deletions
diff --git a/a b/a
new file mode 100755
index 0000000..c3ca5c3
--- /dev/null
+++ b/a
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");
+ }
+}