回答編集履歴
2
fix array index
test
CHANGED
@@ -60,7 +60,7 @@
|
|
60
60
|
|
61
61
|
fscanf(fp, "%d\n", &score);
|
62
62
|
|
63
|
-
if (score >= 0) { score_arr[
|
63
|
+
if (score >= 0) { score_arr[count] = score; count++; }
|
64
64
|
|
65
65
|
}
|
66
66
|
|
1
fix access out of bound by tracking count
test
CHANGED
@@ -52,19 +52,21 @@
|
|
52
52
|
|
53
53
|
int score_arr[200];
|
54
54
|
|
55
|
+
int count = 0;
|
56
|
+
|
55
57
|
for (int i = 0; i < 200; i++) {
|
56
58
|
|
57
59
|
int score = 0;
|
58
60
|
|
59
61
|
fscanf(fp, "%d\n", &score);
|
60
62
|
|
61
|
-
if (score >= 0) { score_arr[i] = score; }
|
63
|
+
if (score >= 0) { score_arr[i] = score; count++; }
|
62
64
|
|
63
65
|
}
|
64
66
|
|
65
67
|
|
66
68
|
|
67
|
-
for (int i = 0; i <
|
69
|
+
for (int i = 0; i < count; i++) {
|
68
70
|
|
69
71
|
// データ処理
|
70
72
|
|