質問編集履歴

2

五点目の質問を追加させていただきました。よろしくお願いいたします。

2019/02/17 13:24

投稿

h_proc
h_proc

スコア68

test CHANGED
File without changes
test CHANGED
@@ -3,6 +3,8 @@
3
3
  ```c
4
4
 
5
5
  #include<stdio.h>
6
+
7
+ #include<string.h>
6
8
 
7
9
  #include<stdlib.h>
8
10
 
@@ -126,4 +128,40 @@
126
128
 
127
129
  ```
128
130
 
131
+ 五点目、player_tへのポインタを受け取り、先頭から順にメンバリストの名前のみを表示させる関数を書きたいです。この時、受け取ったポインタが先頭かどうか確認させたいです。このようなコードをかいたのですが、無限ループのような状態になってしまいます。どこが間違っているのでしょうか。
132
+
133
+ ```c
134
+
135
+ void paty(player_t *play){
136
+
137
+ player_t *start;
138
+
139
+ int i = 0;
140
+
141
+ for (i = 0; play!=NULL; i++) {
142
+
143
+ if (i = 0) {
144
+
145
+ play = malloc(sizeof(player_t));
146
+
147
+ start = play;
148
+
149
+ printf("名前を表示できませんでした。\n");
150
+
151
+ }
152
+
153
+ else {
154
+
155
+ play->next = malloc(sizeof(player_t));
156
+
157
+ play = play->next;
158
+
159
+ prinf("名前は%s\n", play->name);
160
+
161
+ }
162
+
163
+ }
164
+
165
+ ```
166
+
129
167
  まったく投げやりな質問になってしまって申し訳ございません。構造体のリストとポインタの関係だけでも教えていただけると嬉しいです。よろしくお願い致します。

1

質問一つ目と二つ目のコードを書き直しました。

2019/02/17 13:24

投稿

h_proc
h_proc

スコア68

test CHANGED
File without changes
test CHANGED
@@ -76,17 +76,19 @@
76
76
 
77
77
  ```c
78
78
 
79
- void paty_ch(player_t *play, int *chara);
79
+ void paty_ch(player_t *play, char *chara);
80
80
 
81
81
 
82
82
 
83
- void paty_ch(player_t *play, int *chara) {
83
+ void paty_ch(player_t *play, char *chara) {
84
84
 
85
- player_t play;
85
+ player_t *play=&chara;
86
86
 
87
- play->next = *chara;
87
+ play->next = &play;
88
88
 
89
89
  }
90
+
91
+
90
92
 
91
93
  ```
92
94
 
@@ -94,13 +96,15 @@
94
96
 
95
97
  ```c
96
98
 
97
- double paty_id(player_t *play, int *id);
99
+ char paty_id(player_t *play, int *id);
98
100
 
99
101
 
100
102
 
101
- double paty_id(player_t *play, int *id) {
103
+ char paty_id(player_t *play, int *id) {
102
104
 
103
- play->id;
105
+ play->id = &id;
106
+
107
+ return play->name;
104
108
 
105
109
  }
106
110