質問編集履歴

4

修正

2020/06/05 12:47

投稿

junnnnchan
junnnnchan

スコア26

test CHANGED
File without changes
test CHANGED
@@ -288,6 +288,6 @@
288
288
 
289
289
  警告を消すには、どう直したらよいでしょうか。
290
290
 
291
- scanfとtype argument of ‘->’の解決策がわかりません。
291
+ scanfの警告の解決策がわかりません。
292
292
 
293
293
  よりよい解決策をご教示お願いします。

3

修正

2020/06/05 12:47

投稿

junnnnchan
junnnnchan

スコア26

test CHANGED
File without changes
test CHANGED
@@ -274,29 +274,13 @@
274
274
 
275
275
  ```
276
276
 
277
- main.c: In function ‘main’:
278
-
279
- main.c:103:12: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char **’ [-Wformat=]
277
+ main.c:103:12: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char **’ [-Wformat=]
280
-
281
- scanf("%s",x.name);
278
+
282
-
283
- ^
284
-
285
- main.c:112:73: error: invalid type argument of ‘->(have ‘PhysCheckStack {aka struct }’)
279
+ main.c:112:41: warning: format ‘%s’ expects argument of type char *, but argument 2 has typechar **’ [-Wformat=]
286
-
287
- printf("ポップしたデータは%s %.1f %d です。\n", x.name[s->ptr],x.body.vision,x.body.height);
280
+
288
-
289
- ^~
290
-
291
- main.c:118:73: error: invalid type argument of ‘->(have ‘PhysCheckStack {aka struct }’)
281
+ main.c:118:41: warning: format ‘%s’ expects argument of type char *, but argument 2 has typechar **’ [-Wformat=]
292
-
293
- printf("ピークしたデータは%s %.1f %d です。\n", x.name[s->ptr],x.body.vision,x.body.height);
282
+
294
-
295
- ^~
296
-
297
- main.c:124:12: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char **’ [-Wformat=]
283
+ main.c:124:12: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char **’ [-Wformat=]
298
-
299
- scanf("%s",x.name);
300
284
 
301
285
 
302
286
 

2

修正

2020/06/05 12:44

投稿

junnnnchan
junnnnchan

スコア26

test CHANGED
File without changes
test CHANGED
@@ -50,9 +50,9 @@
50
50
 
51
51
  for(int i = 0 ; i < s->ptr ; i ++){
52
52
 
53
- if(strcmp(x->name,s->stk[i].name) == 0){//string compare 文字一致したら0返す
53
+ if(strcmp(x->name[s->ptr],s->stk[i].name[s->ptr]) == 0){//string compare 文字一致したら0返す
54
-
54
+
55
- printf("%s %f %d\n",s->stk[i].name,s->stk[i].body.vision,s->stk[i].body.height);
55
+ printf("%s %f %d\n",s->stk[i].name[s->ptr],s->stk[i].body.vision,s->stk[i].body.height);
56
56
 
57
57
  count ++;
58
58
 
@@ -92,9 +92,9 @@
92
92
 
93
93
  if (s->ptr >= s->max) return -1; /* スタック満杯 */
94
94
 
95
- strcpy(s->stk[s->ptr].name,x->name);
95
+ strcpy(s->stk[s->ptr].name[s->ptr],x->name[s->ptr]);
96
-
96
+
97
- if ((s->stk[s->ptr].name[s->ptr] = calloc(strlen(x)+1, sizeof(char))) == NULL)
97
+ if ((s->stk[s->ptr].name[s->ptr] = calloc(strlen(x->name[s->ptr])+1, sizeof(char*))) == NULL)
98
98
 
99
99
  /* データをコピーするための動的な文字列保存用配列を確保することに失敗 */
100
100
 
@@ -118,13 +118,13 @@
118
118
 
119
119
  s->ptr--;
120
120
 
121
- strcpy(x->name,s->stk[s->ptr].name);
121
+ strcpy(x->name[s->ptr],s->stk[s->ptr].name[s->ptr]);
122
122
 
123
123
  x->body.vision = s->stk[s->ptr].body.vision;
124
124
 
125
125
  x->body.height = s->stk[s->ptr].body.height;
126
126
 
127
- free(s->stk[s->ptr].name);
127
+ free(s->stk[s->ptr].name[s->ptr]);
128
128
 
129
129
  return (0);
130
130
 
@@ -136,7 +136,7 @@
136
136
 
137
137
  if (s->ptr <= 0) return -1;
138
138
 
139
- strcpy(x->name,s->stk[s->ptr-1].name);
139
+ strcpy(x->name[s->ptr],s->stk[s->ptr-1].name[s->ptr]);
140
140
 
141
141
  x->body.vision = s->stk[s->ptr-1].body.vision;
142
142
 
@@ -172,7 +172,7 @@
172
172
 
173
173
  for(i = 0; i < s->ptr; i++)
174
174
 
175
- printf("%s %f %d", s->stk[i].name,s->stk[i].body.vision,s->stk[i].body.height);
175
+ printf("%s %f %d", s->stk[i].name[s->ptr],s->stk[i].body.vision,s->stk[i].body.height);
176
176
 
177
177
  putchar('\n');
178
178
 
@@ -224,7 +224,7 @@
224
224
 
225
225
  else
226
226
 
227
- printf("ポップしたデータは%s %.1f %d です。\n", x.name,x.body.vision,x.body.height);
227
+ printf("ポップしたデータは%s %.1f %d です。\n", x.name[s->ptr],x.body.vision,x.body.height);
228
228
 
229
229
  break;
230
230
 
@@ -236,7 +236,7 @@
236
236
 
237
237
  else
238
238
 
239
- printf("ピークしたデータは%s %.1f %d です。\n", x.name,x.body.vision,x.body.height);
239
+ printf("ピークしたデータは%s %.1f %d です。\n", x.name[s->ptr],x.body.vision,x.body.height);
240
240
 
241
241
  break;
242
242
 
@@ -272,78 +272,38 @@
272
272
 
273
273
 
274
274
 
275
- ```
276
-
277
- <警告>
278
-
279
- main.c:25:13: warning: passing argument 1 of ‘strcmpfrom incompatible
280
-
281
- pointer type [-Wincompatible-pointer-types]
282
-
283
- /usr/include/string.h:144:12: note: expected ‘const char *’ but argumen
284
-
285
- t is of type ‘char **
286
-
287
- main.c:26:13: warning: format %s’ expects argument of type ‘char *’, b
288
-
289
- ut argument 2 has type ‘char **’ [-Wformat=]
290
-
291
-
292
-
293
- /usr/include/string.h:129:14: note: expected ‘char * restrict’ but argu
294
-
295
- ment is of type ‘char **’
296
-
297
- main.c:46:29: warning: passing argument 2 of ‘strcpyfrom incompatible
298
-
299
- pointer type [-Wincompatible-pointer-types]
300
-
301
- /usr/include/string.h:129:14: note: expected ‘const char * restrict’ bu
302
-
303
- t argument is of type ‘char **’
304
-
305
- main.c:47:51: warning: passing argument 1 of ‘strlen’ from incompatible
306
-
307
- pointer type [-Wincompatible-pointer-types]
308
-
309
- /usr/include/string.h:399:15: note: expected ‘const char *’ but argumen
310
-
311
- t is of type ‘PhysCheck * {aka struct <anonymous> *}’
312
-
313
-
314
-
315
-
316
-
317
- /usr/include/string.h:129:14: note: expected ‘const char * restrict’ bu
318
-
319
- t argument is of type ‘char **’
320
-
321
- /usr/include/string.h:129:14: note: expected ‘char * restrict’ but argu
322
-
323
- ment is of type ‘char **’
324
-
325
- main.c:68:17: warning: passing argument 2 of ‘strcpy’ from incompatible
326
-
327
- pointer type [-Wincompatible-pointer-types]
328
-
329
- /usr/include/string.h:129:14: note: expected ‘const char * restrict’ bu
330
-
331
- t argument is of type ‘char **’
332
-
333
- main.c:86:12: warning: format ‘%s’ expects argument of type ‘char *’, b
334
-
335
- ut argument 2 has type ‘char * const*’ [-Wformat=]
336
-
337
- main.c:103:12: warning: format ‘%s’ expects argument of type ‘char *’,
338
-
339
- but argument 2 has type ‘char **’ [-Wformat=]
340
-
341
-
342
-
343
- -----似た警告は省略させていただきます------
275
+ ```
276
+
277
+ main.c: In function ‘main’:
278
+
279
+ main.c:103:12: warning: format ‘%s’ expects argument of type char *, but argument 2 has type ‘char **’ [-Wformat=]
280
+
281
+ scanf("%s",x.name);
282
+
283
+ ^
284
+
285
+ main.c:112:73: error: invalid type argument of ‘->(have ‘PhysCheckStack {aka struct }’)
286
+
287
+ printf("ポップしたデータは%s %.1f %d です。\n", x.name[s->ptr],x.body.vision,x.body.height);
288
+
289
+ ^~
290
+
291
+ main.c:118:73: error: invalid type argument of ‘->’ (have ‘PhysCheckStack {aka struct }’)
292
+
293
+ printf("ピークしたデータは%s %.1f %d です。\n", x.name[s->ptr],x.body.vision,x.body.height);
294
+
295
+ ^~
296
+
297
+ main.c:124:12: warning: format ‘%s’ expects argument of type char *, but argument 2 has type ‘char **’ [-Wformat=]
298
+
299
+ scanf("%s",x.name);
300
+
301
+
344
302
 
345
303
  <質問>
346
304
 
347
305
  警告を消すには、どう直したらよいでしょうか。
348
306
 
349
- 型が間違っている警告されているですが、一つの型を直すと、コードの多箇所に影響すると考えてます。よりよい解決策をご教示お願いし
307
+ scanftype argument of ‘->’の解決策がわかりせん
308
+
309
+ よりよい解決策をご教示お願いします。

1

追記

2020/06/05 12:24

投稿

junnnnchan
junnnnchan

スコア26

test CHANGED
File without changes
test CHANGED
@@ -1,3 +1,5 @@
1
+ <追記>
2
+
1
3
  ```
2
4
 
3
5
  #include <stdio.h>
@@ -70,7 +72,7 @@
70
72
 
71
73
  s->ptr = 0;
72
74
 
73
- if ((s->stk[s->ptr].name = calloc(max, sizeof(char))) == NULL) {
75
+ if ((s->stk[s->ptr].name[s->ptr] = calloc(max, sizeof(char*))) == NULL) {
74
76
 
75
77
  s->max = 0; /* char* の配列の確保に失敗 */
76
78
 
@@ -92,7 +94,7 @@
92
94
 
93
95
  strcpy(s->stk[s->ptr].name,x->name);
94
96
 
95
- if ((s->stk[s->ptr].name = calloc(strlen(x)+1, sizeof(char))) == NULL)
97
+ if ((s->stk[s->ptr].name[s->ptr] = calloc(strlen(x)+1, sizeof(char))) == NULL)
96
98
 
97
99
  /* データをコピーするための動的な文字列保存用配列を確保することに失敗 */
98
100
 
@@ -272,16 +274,76 @@
272
274
 
273
275
  ```
274
276
 
275
- エラー文
276
-
277
- main.c:47:27: error: assignment to expression with array type
278
-
279
- if ((s->stk[s->ptr].name = calloc(strlen(x)+1, sizeof(char))) == NULL)
280
-
281
- main.c:36:27: error: assignment to expression with array type
282
-
283
- if ((s->stk[s->ptr].name = calloc(max, sizeof(char ))) == NULL) {
284
-
285
- ^
286
-
287
- と出てるのですが、配列と型が違うという意味らしいですが、理解できません。なぜ違うのか知りたいです。よろしくお願いします。
277
+ <警告>
278
+
279
+ main.c:25:13: warning: passing argument 1 of ‘strcmp’ from incompatible
280
+
281
+ pointer type [-Wincompatible-pointer-types]
282
+
283
+ /usr/include/string.h:144:12: note: expected ‘const char *’ but argumen
284
+
285
+ t is of type char **’
286
+
287
+ main.c:26:13: warning: format ‘%s’ expects argument of type ‘char *’, b
288
+
289
+ ut argument 2 has type ‘char **’ [-Wformat=]
290
+
291
+
292
+
293
+ /usr/include/string.h:129:14: note: expected ‘char * restrict’ but argu
294
+
295
+ ment is of type ‘char **’
296
+
297
+ main.c:46:29: warning: passing argument 2 of ‘strcpy’ from incompatible
298
+
299
+ pointer type [-Wincompatible-pointer-types]
300
+
301
+ /usr/include/string.h:129:14: note: expected ‘const char * restrict’ bu
302
+
303
+ t argument is of type ‘char **’
304
+
305
+ main.c:47:51: warning: passing argument 1 of ‘strlen’ from incompatible
306
+
307
+ pointer type [-Wincompatible-pointer-types]
308
+
309
+ /usr/include/string.h:399:15: note: expected ‘const char *’ but argumen
310
+
311
+ t is of type ‘PhysCheck * {aka struct <anonymous> *}’
312
+
313
+
314
+
315
+
316
+
317
+ /usr/include/string.h:129:14: note: expected ‘const char * restrict’ bu
318
+
319
+ t argument is of type ‘char **’
320
+
321
+ /usr/include/string.h:129:14: note: expected ‘char * restrict’ but argu
322
+
323
+ ment is of type ‘char **’
324
+
325
+ main.c:68:17: warning: passing argument 2 of ‘strcpy’ from incompatible
326
+
327
+ pointer type [-Wincompatible-pointer-types]
328
+
329
+ /usr/include/string.h:129:14: note: expected ‘const char * restrict’ bu
330
+
331
+ t argument is of type ‘char **’
332
+
333
+ main.c:86:12: warning: format ‘%s’ expects argument of type ‘char *’, b
334
+
335
+ ut argument 2 has type ‘char * const*’ [-Wformat=]
336
+
337
+ main.c:103:12: warning: format ‘%s’ expects argument of type ‘char *’,
338
+
339
+ but argument 2 has type ‘char **’ [-Wformat=]
340
+
341
+
342
+
343
+ -----似た警告は省略させていただきます------
344
+
345
+ <質問>
346
+
347
+ 警告を消すには、どう直したらよいでしょうか。
348
+
349
+ 型が間違っていると警告されているのですが、一つの型を直すと、コードの多箇所に影響すると考えてます。よりよい解決策をご教示お願いします。