質問編集履歴

4

初心者マークの追加

2019/07/18 06:35

投稿

mudannkesseki
mudannkesseki

スコア16

test CHANGED
File without changes
test CHANGED
@@ -420,4 +420,4 @@
420
420
 
421
421
 
422
422
 
423
- warningとnoteの改善策もよければ教えていただきたいです
423
+ warningとnoteの改善策もよければ教えていただきたいです

3

プログラムの追加

2019/07/18 06:35

投稿

mudannkesseki
mudannkesseki

スコア16

test CHANGED
File without changes
test CHANGED
@@ -24,6 +24,12 @@
24
24
 
25
25
 
26
26
 
27
+
28
+
29
+
30
+
31
+ **元のプログラム↓**
32
+
27
33
  ```C言語
28
34
 
29
35
  #include<stdio.h>
@@ -214,4 +220,204 @@
214
220
 
215
221
 
216
222
 
223
+ **修正したプログラム↓**
224
+
225
+
226
+
227
+ ```C言語
228
+
229
+ #include<stdio.h>
230
+
231
+ #include<stdlib.h>
232
+
233
+ #include<string.h>
234
+
235
+
236
+
237
+ int strcmp(const char *s1,const char *s2);
238
+
239
+ struct node{
240
+
241
+ char word[50];
242
+
243
+ int kaisu;
244
+
245
+ struct node *left;
246
+
247
+ struct node *right;
248
+
249
+ };
250
+
251
+
252
+
253
+ char wd[50];
254
+
255
+
256
+
257
+ char *GetWord()
258
+
259
+ {
260
+
261
+ char a;
262
+
263
+ int len;
264
+
265
+
266
+
267
+ a=getchar();
268
+
269
+ while(a==' ' || a=='\n') a=getchar();
270
+
271
+ len=0;
272
+
273
+ while(a!=' ' && a!='\n'){
274
+
275
+ wd[len++]=a;
276
+
277
+ a=getchar();
278
+
279
+ }
280
+
281
+ wd[len]='\0';
282
+
283
+ return &wd[0];
284
+
285
+ }
286
+
287
+
288
+
289
+ struct node *insert(struct node *x,char a)
290
+
291
+ {
292
+
293
+ if(x==NULL){
294
+
295
+ x=(struct node *)malloc(sizeof(struct node));
296
+
297
+ x->word=a;
298
+
299
+ x->kaisu=1;
300
+
301
+ x->left=NULL;
302
+
303
+ x->right=NULL;
304
+
305
+ }else if(strcmp(a,x->word)==0)
306
+
307
+ x->kaisu++;
308
+
309
+ else if(strcmp(a,x->word)<0)
310
+
311
+ x->left=insert(x->left,a);
312
+
313
+ else
314
+
315
+ x->right=insert(x->right,a);
316
+
317
+ return x;
318
+
319
+ }
320
+
321
+
322
+
323
+ void treeprint(struct node *x)
324
+
325
+ {
326
+
327
+ if(x!=NULL){
328
+
329
+ treeprint(x->left);
330
+
331
+ printf("%s %d\n",x->word,x->kaisu);
332
+
333
+ treeprint(x->right);
334
+
335
+ }
336
+
337
+ }
338
+
339
+
340
+
341
+ int main(void)
342
+
343
+ {
344
+
345
+ struct node *root;
346
+
347
+ char *w;
348
+
349
+
350
+
351
+ root=NULL;
352
+
353
+ w=GetWord();
354
+
355
+ while(strcmp(w,"***END***")!=0){
356
+
357
+ root=insert(root,w);
358
+
359
+ w=GetWord();
360
+
361
+ }
362
+
363
+ treeprint(root);
364
+
365
+ return 0;
366
+
367
+ }
368
+
369
+ ```
370
+
371
+ エラーコード
372
+
373
+ > getword2.c: In function ‘insert’:
374
+
375
+ getword2.c:35:12: error: assignment to expression with array type
376
+
377
+ x->word=a;
378
+
379
+ ^
380
+
381
+ getword2.c:39:19: warning: passing argument 1 of ‘strcmp’ makes pointer from integer without a cast [-Wint-conversion]
382
+
383
+ }else if(strcmp(a,x->word)==0)
384
+
385
+ ^
386
+
387
+ In file included from getword2.c:3:0:
388
+
389
+ /usr/include/string.h:140:12: note: expected ‘const char *’ but argument is of type ‘char’
390
+
391
+ extern int strcmp (const char *__s1, const char *__s2)
392
+
393
+ ^
394
+
395
+ getword2.c:41:19: warning: passing argument 1 of ‘strcmp’ makes pointer from integer without a cast [-Wint-conversion]
396
+
397
+ else if(strcmp(a,x->word)<0)
398
+
399
+ ^
400
+
401
+ In file included from getword2.c:3:0:
402
+
403
+ /usr/include/string.h:140:12: note: expected ‘const char *’ but argument is of type ‘char’
404
+
405
+ extern int strcmp (const char *__s1, const char *__s2)
406
+
407
+ ^
408
+
409
+ getword2.c: In function ‘main’:
410
+
411
+ getword2.c:65:24: warning: passing argument 2 of ‘insert’ makes integer from pointer without a cast [-Wint-conversion]
412
+
413
+ root=insert(root,w);
414
+
415
+ ^
416
+
417
+ getword2.c:31:14: note: expected ‘char’ but argument is of type ‘char *’
418
+
419
+ struct node *insert(struct node *x,char a)
420
+
421
+
422
+
217
- 出力結果の改善と、warningとnoteの改善策もよければ教えていただきたいです。
423
+ warningとnoteの改善策もよければ教えていただきたいです。

2

コードの挿入

2019/07/18 06:35

投稿

mudannkesseki
mudannkesseki

スコア16

test CHANGED
File without changes
test CHANGED
@@ -136,6 +136,40 @@
136
136
 
137
137
  }
138
138
 
139
+ }
140
+
141
+
142
+
143
+ int main(void)
144
+
145
+ {
146
+
147
+ struct node *root;
148
+
149
+ char *w;
150
+
151
+
152
+
153
+ root=NULL;
154
+
155
+ w=GetWord();
156
+
157
+ while(strcmp(w,"***END***")!=0){
158
+
159
+ root=insert(root,w);
160
+
161
+ w=GetWord();
162
+
163
+ }
164
+
165
+ treeprint(root);
166
+
167
+ return 0;
168
+
169
+ }
170
+
171
+
172
+
139
173
  ```
140
174
 
141
175
 

1

誤字

2019/07/18 01:12

投稿

mudannkesseki
mudannkesseki

スコア16

test CHANGED
@@ -1 +1 @@
1
- 出力時の文字化け改善方法
1
+ 出力時の文字化け改善したいです。
test CHANGED
File without changes