回答編集履歴
1
1
answer
CHANGED
@@ -1,2 +1,29 @@
|
|
1
1
|
とりあえず、変数 type の更新は関数 updateWord 内から main に移しましょう。
|
2
|
-
場所は、関数 updateWord を呼んだ次あたりに。
|
2
|
+
場所は、関数 updateWord を呼んだ次あたりに。
|
3
|
+
--- 追記 ---
|
4
|
+
たとえばmainのループをこんな感じにしたら
|
5
|
+
```c++
|
6
|
+
while (!file.eof()) {
|
7
|
+
letter++;
|
8
|
+
updateWord();
|
9
|
+
if (isspace(ch)) {
|
10
|
+
type = B;
|
11
|
+
else {
|
12
|
+
type = N;
|
13
|
+
}
|
14
|
+
if (ch == '\n') {
|
15
|
+
line++;
|
16
|
+
}
|
17
|
+
ch = file.get();
|
18
|
+
}
|
19
|
+
```
|
20
|
+
関数内はこんな感じになりますね。
|
21
|
+
```c++
|
22
|
+
void updateWord(void) {
|
23
|
+
if (isspace(ch)) {
|
24
|
+
if (type == N) {
|
25
|
+
word++;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
```
|