回答編集履歴

2

追記

2018/05/26 08:48

投稿

cateye
cateye

スコア6851

test CHANGED
@@ -107,3 +107,73 @@
107
107
 
108
108
 
109
109
  ```
110
+
111
+ 「追記」こういったこと?
112
+
113
+ ```c
114
+
115
+ #include <stdio.h>
116
+
117
+
118
+
119
+ typedef struct {
120
+
121
+ int no1;
122
+
123
+ int no2;
124
+
125
+ } person1;
126
+
127
+
128
+
129
+ void print(const person1 * const pp)
130
+
131
+ {
132
+
133
+ if( pp->no1 != 0){
134
+
135
+ printf("%d\n", pp->no1);
136
+
137
+ print(pp+1);
138
+
139
+ }
140
+
141
+ }
142
+
143
+
144
+
145
+ int main(void){
146
+
147
+
148
+
149
+ // 構造体配列に初期値セット
150
+
151
+ person1 person[] = {
152
+
153
+ {1,2},
154
+
155
+ {2,3},
156
+
157
+ {0,0}
158
+
159
+ };
160
+
161
+
162
+
163
+ print(person);
164
+
165
+
166
+
167
+ return 0;
168
+
169
+ }
170
+
171
+ ```
172
+
173
+ usr~/test % ./a.out
174
+
175
+ 1
176
+
177
+ 2
178
+
179
+ usr~/test %

1

追記

2018/05/26 08:47

投稿

cateye
cateye

スコア6851

test CHANGED
@@ -39,3 +39,71 @@
39
39
 
40
40
 
41
41
  ```
42
+
43
+ 題意とは違うと思いますが、再起を使うと・・・
44
+
45
+ ```c
46
+
47
+ #include <stdio.h>
48
+
49
+
50
+
51
+ typedef struct {
52
+
53
+ int no1;
54
+
55
+ int no2;
56
+
57
+ } person1;
58
+
59
+
60
+
61
+ void print(person1 *pp)
62
+
63
+ {
64
+
65
+ if( pp->no1== 0){
66
+
67
+ return;
68
+
69
+ }
70
+
71
+ printf("%d\n", pp->no1);
72
+
73
+ //
74
+
75
+ print(++pp);
76
+
77
+ }
78
+
79
+
80
+
81
+ int main(void){
82
+
83
+
84
+
85
+ // 構造体配列に初期値セット
86
+
87
+ person1 person[] = {
88
+
89
+ {1,2},
90
+
91
+ {2,3},
92
+
93
+ {0,0}
94
+
95
+ };
96
+
97
+
98
+
99
+ print(person);
100
+
101
+
102
+
103
+ return 0;
104
+
105
+ }
106
+
107
+
108
+
109
+ ```