回答編集履歴

4

tfree 追加

2022/07/08 03:35

投稿

jimbe
jimbe

スコア12646

test CHANGED
@@ -82,6 +82,14 @@
82
82
  return root;
83
83
  }
84
84
 
85
+ void tfree(CELL *p) {
86
+ if(p == NULL) return;
87
+
88
+ tfree(p->right);
89
+ tfree(p->left);
90
+ free(p);
91
+ }
92
+
85
93
  int input(char *buf) {
86
94
  printf("\n単語, または00を入力して下さい(00なら終了します): ");
87
95
  scanf("%s", buf);
@@ -102,6 +110,7 @@
102
110
  }
103
111
  printf("終了します.\n");
104
112
 
113
+ tfree(root);
105
114
  exit(0);
106
115
  }
107
116
  ```

3

大文字化で無く小文字化でした

2022/07/07 19:36

投稿

jimbe
jimbe

スコア12646

test CHANGED
@@ -67,7 +67,7 @@
67
67
  char str[256];
68
68
  while((c = fgetc(fp)) != EOF) {
69
69
  if(c > ' ' && !strchr(SEPARATORS, c)) {
70
- str[i++] = toupper(c);
70
+ str[i++] = tolower(c);
71
71
  str[i] = '\0';
72
72
  continue;
73
73
  }
@@ -110,60 +110,60 @@
110
110
  **************************
111
111
  入力ファイル名: test.txt
112
112
 
113
- SECTION
113
+ section
114
114
  1
115
- FULL
115
+ full
116
- FAITH
116
+ faith
117
- AND
117
+ and
118
- CREDIT
118
+ credit
119
- SHALL
119
+ shall
120
- BE
120
+ be
121
- GIVEN
121
+ given
122
- IN
122
+ in
123
123
  :
124
124
  (中略)
125
125
  :
126
- BE
126
+ be
127
- REMOVED
127
+ removed
128
- TO
128
+ to
129
- THE
129
+ the
130
- STATE
130
+ state
131
- HAVING
131
+ having
132
- JURISDICTION
132
+ jurisdiction
133
- OF
133
+ of
134
- THE
134
+ the
135
- CRIME
135
+ crime
136
136
  *** 単語の出現頻度 ***
137
137
  1 1
138
138
  1 2
139
- 1 A
139
+ 1 a
140
- 2 ACTS
140
+ 2 acts
141
- 1 ALL
141
+ 1 all
142
- 7 AND
142
+ 7 and
143
- 1 ANOTHER
143
+ 1 another
144
- 1 ANY
144
+ 1 any
145
- 1 AUTHORITY
145
+ 1 authority
146
- 6 BE
146
+ 6 be
147
147
  :
148
148
  (中略)
149
149
  :
150
- 1 STATES
150
+ 1 states
151
- 1 SUCH
151
+ 1 such
152
- 10 THE
152
+ 10 the
153
- 1 THEREOF
153
+ 1 thereof
154
- 4 TO
154
+ 4 to
155
- 1 TREASON
155
+ 1 treason
156
- 1 UP
156
+ 1 up
157
- 2 WHICH
157
+ 2 which
158
- 1 WHO
158
+ 1 who
159
- 1 WITH
159
+ 1 with
160
160
  68種類の単語を登録
161
161
 
162
- 単語, または00を入力して下さい(00なら終了します): THE
162
+ 単語, または00を入力して下さい(00なら終了します): the
163
- THEの出現頻度: 10
163
+ theの出現頻度: 10
164
164
 
165
- 単語, または00を入力して下さい(00なら終了します): ABC
165
+ 単語, または00を入力して下さい(00なら終了します): abc
166
- ABCの単語は登録されていません!
166
+ abcの単語は登録されていません!
167
167
 
168
168
  単語, または00を入力して下さい(00なら終了します): 00
169
169
  終了します.

2

toupper を利用

2022/07/07 19:20

投稿

jimbe
jimbe

スコア12646

test CHANGED
@@ -2,6 +2,7 @@
2
2
  #include <stdio.h>
3
3
  #include <stdlib.h>
4
4
  #include <string.h>
5
+ #include <ctype.h>
5
6
 
6
7
  #define SEPARATORS ",.':;()"
7
8
 
@@ -66,8 +67,7 @@
66
67
  char str[256];
67
68
  while((c = fgetc(fp)) != EOF) {
68
69
  if(c > ' ' && !strchr(SEPARATORS, c)) {
69
- if('a' <= c && c <= 'z') c -= 'a' - 'A';
70
- str[i++] = c;
70
+ str[i++] = toupper(c);
71
71
  str[i] = '\0';
72
72
  continue;
73
73
  }

1

修正

2022/07/07 19:07

投稿

jimbe
jimbe

スコア12646

test CHANGED
@@ -25,7 +25,7 @@
25
25
 
26
26
  int a = strcmp(name, p->key);
27
27
  if(a == 0) {
28
- p->count += 1;
28
+ p->count ++;
29
29
  } else {
30
30
  CELL **q = TBRANCH(a, p);
31
31
  *q = tinsert(*q, name);