回答編集履歴
2
説明を追加
test
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
```C
|
18
18
|
|
19
|
-
#include <stdio.h> //puts
|
19
|
+
#include <stdio.h> // puts
|
20
20
|
|
21
21
|
#include <stdlib.h> // malloc, free
|
22
22
|
|
@@ -42,7 +42,7 @@
|
|
42
42
|
|
43
43
|
static char gcp[3][9] = { "rock", "scissors", "paper" };
|
44
44
|
|
45
|
-
HAND cpu, *you;
|
45
|
+
HAND cpu, *you; // cpu は実体、you はポインタ
|
46
46
|
|
47
47
|
|
48
48
|
|
@@ -63,3 +63,19 @@
|
|
63
63
|
}
|
64
64
|
|
65
65
|
```
|
66
|
+
|
67
|
+
**追記**
|
68
|
+
|
69
|
+
`static char gcp[3][9] = { "rock", "scissors", "paper" };` を用意しなくても
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
`memcpy(cpu.gcp, (char[3][9]){"rock","scissors","paper"}, sizeof cpu.gcp);`
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
と書けるようです。
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
`sizeof cpu.gcp` は `sizeof(char[3][9])` でもかまいません。
|
1
static の追加
test
CHANGED
@@ -40,7 +40,7 @@
|
|
40
40
|
|
41
41
|
{
|
42
42
|
|
43
|
-
char gcp[3][9] = { "rock", "scissors", "paper" };
|
43
|
+
static char gcp[3][9] = { "rock", "scissors", "paper" };
|
44
44
|
|
45
45
|
HAND cpu, *you;
|
46
46
|
|