質問編集履歴
9
c言語とコードの初めに入れる
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,7 +14,9 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
|
17
|
-
```
|
17
|
+
```
|
18
|
+
|
19
|
+
c言語
|
18
20
|
|
19
21
|
/* ラックナンバーサーチ・トレーニング(過去の履歴と最短時間の表示)*/
|
20
22
|
|
8
タイトルの変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
過去のbestten を表示したいが
|
1
|
+
過去のbestten を表示したいが表示はされるが完全な順序になっていない。
|
test
CHANGED
File without changes
|
7
質問内容の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,8 +1,20 @@
|
|
1
|
-
|
1
|
+
実行結果が時間の短い順になっていない。大体は時間順になっています。
|
2
|
-
|
2
|
+
|
3
|
-
どこを直せばいいでしょうか。
|
3
|
+
どこを直せばいいでしょうか。c言語でかいています。
|
4
|
+
|
4
|
-
|
5
|
+
構造体の定義や、名前のわかりにくさがありますが、とりあえずこれで正常に
|
6
|
+
|
7
|
+
うごくようにしてから、コードの修正をかんがえています。
|
8
|
+
|
9
|
+
もう何回も挑戦してここまでプログラムをつくりました。
|
10
|
+
|
11
|
+
前回作って正常に動くと思っていたのですが、ちゃんと動いていないことがわかり
|
12
|
+
|
13
|
+
苦戦しています(1か月くらい)。よろしくお願いします。
|
14
|
+
|
15
|
+
|
16
|
+
|
5
|
-
```コード
|
17
|
+
``` コード
|
6
18
|
|
7
19
|
/* ラックナンバーサーチ・トレーニング(過去の履歴と最短時間の表示)*/
|
8
20
|
|
6
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
```c言語
|
2
|
-
|
3
1
|
コードをを修正して、過去のデータだけを表示したいのですが、コンパイルは通るのですが、実行で異常終了します。
|
4
2
|
|
5
3
|
どこを直せばいいでしょうか。
|
6
4
|
|
7
|
-
コード
|
5
|
+
```コード
|
6
|
+
|
7
|
+
/* ラックナンバーサーチ・トレーニング(過去の履歴と最短時間の表示)*/
|
8
|
+
|
9
|
+
|
8
10
|
|
9
11
|
#include <stdio.h>
|
10
12
|
|
@@ -20,147 +22,231 @@
|
|
20
22
|
|
21
23
|
#include <unistd.h>
|
22
24
|
|
23
|
-
|
25
|
+
#include "getputch.h"
|
24
|
-
|
26
|
+
|
27
|
+
|
28
|
+
|
25
|
-
#define MAX_STAGE
|
29
|
+
#define MAX_STAGE 3
|
26
|
-
|
30
|
+
|
27
|
-
#define swap(type, x, y)
|
31
|
+
#define swap(type, x, y) do { type t = x; x = y; y = t; } while (0)
|
28
32
|
|
29
33
|
#define MAX_NUM 10
|
30
34
|
|
31
35
|
|
32
36
|
|
33
|
-
char dtfile[] = "LACKNUM.DAT";
|
37
|
+
char dtfile[] = "LACKNUM.DAT";
|
34
|
-
|
35
|
-
|
38
|
+
|
36
|
-
|
37
|
-
// 2012 10 18 17 28 35......前回の終了時刻
|
38
|
-
|
39
|
-
// 31.1000000 ...................前回までの最短時間
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
char dtfile2[] = "LACKNUM2.DAT";
|
39
|
+
char dtfile2[] = "LACKNUM2.DAT";/* 最高記録用のファイル */
|
44
|
-
|
45
|
-
double score2;
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
typedef struct tm TIME_DATA;
|
50
40
|
|
51
41
|
|
52
42
|
|
53
43
|
typedef struct {
|
54
44
|
|
45
|
+
int tm_year;
|
46
|
+
|
55
|
-
|
47
|
+
int tm_mon;
|
48
|
+
|
56
|
-
|
49
|
+
int tm_mday;
|
50
|
+
|
51
|
+
int tm_hour;
|
52
|
+
|
53
|
+
int tm_min;
|
54
|
+
|
55
|
+
int tm_sec;
|
56
|
+
|
57
|
-
double score;
|
57
|
+
double score;
|
58
|
-
|
58
|
+
|
59
|
-
} S
|
59
|
+
} BEST_TEN;
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
-
|
63
|
+
// --------------- 比較用の関数 cmp -------------------
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
|
67
|
-
|
65
|
+
int cmpptr( const void *p, const void *q ) {
|
66
|
+
|
67
|
+
return (*(BEST_TEN**)p)->score - (*(BEST_TEN**)q)->score;
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
// ----------------------------------------------------
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
/*--- 過去のトレーニング情報を取得・表示して最高得点を返す ---*/
|
76
|
+
|
77
|
+
double get_data(int *count)
|
78
|
+
|
79
|
+
{
|
80
|
+
|
81
|
+
FILE *fp; // これまでの履歴を指すポインタ
|
82
|
+
|
83
|
+
FILE *fp2; // これまでの最短所要時間を指すポインタ
|
84
|
+
|
85
|
+
double score; //これまでの履歴の所要時間
|
86
|
+
|
87
|
+
double bestscore; //これまでの最短所要時間
|
88
|
+
|
89
|
+
int i,j=0;
|
90
|
+
|
91
|
+
BEST_TEN best_ten[100]={0};
|
68
92
|
|
69
93
|
|
70
94
|
|
71
|
-
|
95
|
+
if ((fp = fopen(dtfile, "rb")) == NULL) {
|
96
|
+
|
72
|
-
|
97
|
+
printf("ファイルを作成します。\n\n");
|
98
|
+
|
73
|
-
|
99
|
+
bestscore = DBL_MAX; /* float.hに定義されている。double型で表現できる最大値を表すマクロDBL_MAX */
|
100
|
+
|
101
|
+
} else {
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
struct tm local;
|
106
|
+
|
107
|
+
double line[256];
|
74
108
|
|
75
109
|
|
76
110
|
|
111
|
+
printf("\n過去の履歴\n-------------------------- \n");
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
while((i = fread(&local, sizeof(struct tm), 1, fp)) > 0 ){
|
116
|
+
|
117
|
+
printf("%d年 %d月 %d日 %d時 %d分 %d秒\n",
|
118
|
+
|
119
|
+
local.tm_year + 1900, local.tm_mon + 1,
|
120
|
+
|
121
|
+
local.tm_mday, local.tm_hour, local.tm_min, local.tm_sec);
|
122
|
+
|
123
|
+
fread(&score, sizeof(double), 1, fp);
|
124
|
+
|
125
|
+
printf("得点(所要時間)は%.1f秒\n\n", score);
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
best_ten[j].tm_year=local.tm_year;
|
130
|
+
|
131
|
+
best_ten[j].tm_mon=local.tm_mon;
|
132
|
+
|
133
|
+
best_ten[j].tm_mday=local.tm_mday;
|
134
|
+
|
135
|
+
best_ten[j].tm_hour=local.tm_hour;
|
136
|
+
|
137
|
+
best_ten[j].tm_min=local.tm_min;
|
138
|
+
|
139
|
+
best_ten[j].tm_sec=local.tm_sec;
|
140
|
+
|
141
|
+
best_ten[j].score=score;
|
142
|
+
|
143
|
+
j++;
|
144
|
+
|
145
|
+
(*count)++;
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
printf("count1は%d\n\n", *count);
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
BEST_TEN *plst[*count];
|
154
|
+
|
155
|
+
for( i = 0; i < *count; i++ ) plst[i] = &best_ten[i];
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
//qsort(配列名, 配列の数, 配列一つのバイト数, 比較関数)
|
160
|
+
|
161
|
+
qsort( plst, *count, sizeof(BEST_TEN*), cmpptr );
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
printf("\n過去のbestten\n-------------------------- \n");
|
168
|
+
|
169
|
+
// 並べ替え後の内容を表示
|
170
|
+
|
171
|
+
for(i=0;i<10;i++){
|
172
|
+
|
173
|
+
printf( "%d年 %d月 %d日 %d時 %d分 %d秒 \n"
|
174
|
+
|
175
|
+
,plst[i]->tm_year+1900, plst[i]->tm_mon+1, plst[i]->tm_mday,
|
176
|
+
|
177
|
+
plst[i]->tm_hour,plst[i]->tm_min,plst[i]->tm_sec );
|
178
|
+
|
179
|
+
printf("得点(所要時間)は %.1f秒です。\n\n", plst[i]->score);
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
bestscore=plst[0]->score;
|
184
|
+
|
185
|
+
fflush(stdout);
|
186
|
+
|
77
|
-
fclose(fp);
|
187
|
+
fclose(fp);
|
188
|
+
|
189
|
+
printf("count2は%d\n\n", *count);
|
190
|
+
|
191
|
+
return bestscore;
|
78
192
|
|
79
193
|
}
|
80
194
|
|
195
|
+
|
196
|
+
|
197
|
+
|
198
|
+
|
81
|
-
|
199
|
+
int main(void)
|
82
200
|
|
83
201
|
{
|
84
202
|
|
203
|
+
int count=0; //
|
204
|
+
|
205
|
+
double score; // 今回の所要時間
|
206
|
+
|
207
|
+
double bestscore; // 最短所要時間
|
208
|
+
|
209
|
+
double jikan; // 時間
|
210
|
+
|
85
211
|
FILE *fp;
|
86
212
|
|
213
|
+
|
214
|
+
|
87
|
-
|
215
|
+
struct tm local ;
|
216
|
+
|
88
|
-
|
217
|
+
int k;
|
218
|
+
|
219
|
+
int i, j, x, stage;
|
220
|
+
|
221
|
+
bestscore= get_data(&count); // get_data()で前回までの最短所要時間を
|
222
|
+
|
223
|
+
// ファイルから読み込んでbestscoreに代入する。
|
224
|
+
|
89
|
-
if
|
225
|
+
printf("bestscoreは%.1f\n\n", bestscore);
|
90
|
-
|
226
|
+
|
91
|
-
|
227
|
+
printf("count3は%d\n\n", count);
|
92
|
-
|
93
|
-
|
228
|
+
|
94
|
-
|
229
|
+
|
230
|
+
|
95
|
-
|
231
|
+
return 0;
|
96
|
-
|
97
|
-
|
232
|
+
|
98
|
-
|
99
|
-
|
233
|
+
|
100
|
-
|
101
|
-
|
234
|
+
|
102
|
-
|
103
|
-
score_data->time.tm_mday,
|
104
|
-
|
105
|
-
score_data->time.tm_hour,
|
106
|
-
|
107
|
-
score_data->time.tm_min,
|
108
|
-
|
109
|
-
score_data->time.tm_sec );
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
printf("得点(所要時間)は %.1f秒です。\n\n",
|
114
|
-
|
115
|
-
score_data->score );
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
235
|
+
}
|
120
|
-
|
121
|
-
|
236
|
+
|
122
|
-
|
123
|
-
}
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
double get_score(SCORE_DATA *score_data) {
|
128
|
-
|
129
|
-
return score_data->score;
|
130
|
-
|
131
|
-
}
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
int main(void)
|
136
|
-
|
137
|
-
{
|
138
|
-
|
139
|
-
FILE *fp;
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
fp = fopen(dtfile, "rb");
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
print_score_data(score_data);
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
return 0;
|
152
|
-
|
153
|
-
}
|
154
|
-
|
155
|
-
```
|
237
|
+
```
|
156
238
|
|
157
239
|
/*
|
158
240
|
|
241
|
+
|
242
|
+
|
159
|
-
C:\MinGW\users\chap09\kadai>gcc -I. -o kadai9-1-
|
243
|
+
C:\MinGW\users\chap09\kadai>gcc -I. -o kadai9-1-6 kadai9-1-6.c pdcurs
|
244
|
+
|
160
|
-
|
245
|
+
es.a
|
161
|
-
|
162
|
-
|
246
|
+
|
247
|
+
|
248
|
+
|
163
|
-
C:\MinGW\users\chap09\kadai>
|
249
|
+
C:\MinGW\users\chap09\kadai>kadai9-1-5
|
164
250
|
|
165
251
|
|
166
252
|
|
@@ -186,38 +272,94 @@
|
|
186
272
|
|
187
273
|
|
188
274
|
|
275
|
+
省略
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
count1は66
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
過去のbestten
|
286
|
+
|
287
|
+
--------------------------
|
288
|
+
|
289
|
+
2017年 8月 14日 20時 57分 40秒
|
290
|
+
|
291
|
+
得点(所要時間)は 6.0秒です。
|
292
|
+
|
293
|
+
|
294
|
+
|
189
|
-
201
|
295
|
+
2017年 9月 9日 12時 14分 36秒
|
190
|
-
|
296
|
+
|
191
|
-
得点(所要時間)は
|
297
|
+
得点(所要時間)は 6.2秒です。
|
192
|
-
|
193
|
-
|
194
|
-
|
298
|
+
|
299
|
+
|
300
|
+
|
195
|
-
2016年
|
301
|
+
2016年 5月 2日 17時 0分 48秒
|
196
|
-
|
302
|
+
|
197
|
-
得点(所要時間)は
|
303
|
+
得点(所要時間)は 7.0秒です。
|
304
|
+
|
305
|
+
|
306
|
+
|
198
|
-
|
307
|
+
2017年 9月 9日 12時 3分 5秒
|
308
|
+
|
199
|
-
|
309
|
+
得点(所要時間)は 6.1秒です。//ここがおかしい
|
200
|
-
|
310
|
+
|
311
|
+
|
312
|
+
|
201
|
-
2016年 1月 4日 19時
|
313
|
+
2016年 1月 4日 19時 15分 11秒
|
202
|
-
|
314
|
+
|
203
|
-
得点(所要時間)は
|
315
|
+
得点(所要時間)は 8.0秒です。
|
204
316
|
|
205
317
|
|
206
318
|
|
207
319
|
2016年 1月 4日 19時 21分 44秒
|
208
320
|
|
209
|
-
得点(所要時間)は8.0秒
|
321
|
+
得点(所要時間)は 8.0秒です。
|
322
|
+
|
323
|
+
|
324
|
+
|
210
|
-
|
325
|
+
2017年 9月 9日 12時 4分 2秒
|
326
|
+
|
211
|
-
|
327
|
+
得点(所要時間)は 7.5秒です。//ここがおかしい
|
328
|
+
|
329
|
+
|
330
|
+
|
212
|
-
|
331
|
+
2017年 9月 9日 12時 38分 12秒
|
332
|
+
|
333
|
+
得点(所要時間)は 8.0秒です。
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
2016年 1月 31日 21時 12分 13秒
|
338
|
+
|
339
|
+
得点(所要時間)は 8.0秒です。
|
340
|
+
|
341
|
+
|
342
|
+
|
213
|
-
201
|
343
|
+
2017年 9月 9日 11時 28分 59秒
|
214
|
-
|
344
|
+
|
215
|
-
得点(所要時間)は
|
345
|
+
得点(所要時間)は 8.0秒です。
|
216
|
-
|
217
|
-
|
218
|
-
|
346
|
+
|
347
|
+
|
348
|
+
|
219
|
-
|
349
|
+
count2は66
|
350
|
+
|
351
|
+
|
352
|
+
|
220
|
-
|
353
|
+
bestscoreは6.0
|
354
|
+
|
355
|
+
|
356
|
+
|
221
|
-
|
357
|
+
count3は66
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
C:\MinGW\users\chap09\kadai>
|
222
364
|
|
223
365
|
*/
|
5
LousiS0616さんのご指導でコードを修正しましたが、うまく動きません。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,15 +1,11 @@
|
|
1
1
|
```c言語
|
2
2
|
|
3
|
-
|
3
|
+
コードをを修正して、過去のデータだけを表示したいのですが、コンパイルは通るのですが、実行で異常終了します。
|
4
|
-
|
4
|
+
|
5
|
-
|
5
|
+
どこを直せばいいでしょうか。
|
6
6
|
|
7
7
|
コード
|
8
8
|
|
9
|
-
/* ラックナンバーサーチ・トレーニング(最近の10回の日時)*/
|
10
|
-
|
11
|
-
|
12
|
-
|
13
9
|
#include <stdio.h>
|
14
10
|
|
15
11
|
#include <time.h>
|
@@ -24,177 +20,115 @@
|
|
24
20
|
|
25
21
|
#include <unistd.h>
|
26
22
|
|
27
|
-
|
23
|
+
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
|
31
|
-
#define MAX_STAGE
|
25
|
+
#define MAX_STAGE 3
|
32
|
-
|
26
|
+
|
33
|
-
#define swap(type, x, y)
|
27
|
+
#define swap(type, x, y) do{ type t = x; x = y; y = t; } while (0)
|
34
28
|
|
35
29
|
#define MAX_NUM 10
|
36
30
|
|
37
31
|
|
38
32
|
|
39
|
-
char dtfile[] = "LACKNUM.DAT";
|
33
|
+
char dtfile[] = "LACKNUM.DAT"; // ファイル名LACKNUM.DATの形式は 年 / 月 / 日 / 時 / 分 / 秒
|
34
|
+
|
40
|
-
|
35
|
+
//
|
36
|
+
|
37
|
+
// 2012 10 18 17 28 35......前回の終了時刻
|
38
|
+
|
39
|
+
// 31.1000000 ...................前回までの最短時間
|
40
|
+
|
41
|
+
|
42
|
+
|
41
|
-
char dtfile2[] = "LACKNUM2.DAT";/
|
43
|
+
char dtfile2[] = "LACKNUM2.DAT"; // 最高記録用のファイル
|
44
|
+
|
45
|
+
double score2;
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
typedef struct tm TIME_DATA;
|
42
50
|
|
43
51
|
|
44
52
|
|
45
53
|
typedef struct {
|
46
54
|
|
47
|
-
int tm_year;
|
48
|
-
|
49
|
-
|
55
|
+
TIME_DATA time;
|
50
|
-
|
51
|
-
|
56
|
+
|
52
|
-
|
53
|
-
int tm_hour;
|
54
|
-
|
55
|
-
int tm_min;
|
56
|
-
|
57
|
-
int tm_sec;
|
58
|
-
|
59
|
-
double score;
|
57
|
+
double score;
|
60
|
-
|
58
|
+
|
61
|
-
}
|
59
|
+
} SCORE_DATA;
|
62
|
-
|
63
|
-
|
64
|
-
|
60
|
+
|
61
|
+
|
62
|
+
|
65
|
-
|
63
|
+
SCORE_DATA *score_data;
|
66
|
-
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
-
i
|
67
|
+
size_t fread_score_data(SCORE_DATA *score_data, FILE *fp) {
|
68
|
-
|
68
|
+
|
69
|
+
|
70
|
+
|
69
|
-
return (
|
71
|
+
return fread(&score_data->time, sizeof(TIME_DATA), 1, fp)
|
72
|
+
|
70
|
-
|
73
|
+
&& fread(&score_data->score, sizeof(double), 1, fp);
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
fclose(fp);
|
78
|
+
|
71
|
-
}
|
79
|
+
}
|
72
|
-
|
73
|
-
|
80
|
+
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
/*--- 過去のトレーニング情報を取得・表示して最高得点を返す ---*/
|
78
|
-
|
79
|
-
d
|
81
|
+
void print_score_data(SCORE_DATA *score_data)
|
80
82
|
|
81
83
|
{
|
82
84
|
|
83
|
-
FILE *fp; // これまでの履歴を指すポインタ
|
84
|
-
|
85
|
-
FILE *fp2; // これまでの最短所要時間を指すポインタ
|
86
|
-
|
87
|
-
double score; //これまでの履歴の所要時間
|
88
|
-
|
89
|
-
double bestscore; //これまでの最短所要時間
|
90
|
-
|
91
|
-
|
85
|
+
FILE *fp;
|
92
|
-
|
93
|
-
|
86
|
+
|
94
|
-
|
95
|
-
|
87
|
+
|
96
88
|
|
97
89
|
if ((fp = fopen(dtfile, "rb")) == NULL) {
|
98
90
|
|
99
91
|
printf("ファイルを作成します。\n\n");
|
100
92
|
|
101
|
-
|
93
|
+
score = DBL_MAX; /* float.hに定義されている。double型で表現できる最大値を表すマクロDBL_MAX */
|
102
94
|
|
103
95
|
} else {
|
104
96
|
|
105
|
-
|
106
|
-
|
107
|
-
struct tm local;
|
108
|
-
|
109
|
-
double line[256];
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
printf("\n過去の履歴\n-------------------------- \n");
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
while((i = fread(&local, sizeof(struct tm), 1, fp)) > 0 ){
|
118
|
-
|
119
|
-
printf("%d年 %d月 %d日 %d時 %d分 %d秒\n",
|
120
|
-
|
121
|
-
local.tm_year + 1900, local.tm_mon + 1,
|
122
|
-
|
123
|
-
local.tm_mday, local.tm_hour, local.tm_min, local.tm_sec);
|
124
|
-
|
125
|
-
fread(&score, sizeof(double), 1, fp);
|
126
|
-
|
127
|
-
printf("得点(所要時間)は%.1f秒\n\n", score);
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
best_ten[j].tm_year=local.tm_year;
|
132
|
-
|
133
|
-
best_ten[j].tm_mon=local.tm_mon;
|
134
|
-
|
135
|
-
best_ten[j].tm_mday=local.tm_mday;
|
136
|
-
|
137
|
-
best_ten[j].tm_hour=local.tm_hour;
|
138
|
-
|
139
|
-
best_ten[j].tm_min=local.tm_min;
|
140
|
-
|
141
|
-
best_ten[j].tm_sec=local.tm_sec;
|
142
|
-
|
143
|
-
best_ten[j].score=score;
|
144
|
-
|
145
|
-
j++;
|
146
|
-
|
147
|
-
(*count)++;
|
148
|
-
|
149
|
-
}
|
150
|
-
|
151
|
-
printf("count1は%d\n\n", *count);
|
152
|
-
|
153
|
-
}
|
154
|
-
|
155
|
-
BEST_TEN *plst[*count];
|
156
|
-
|
157
|
-
for( i = 0; i < *count; i++ ) plst[i] = &best_ten[i];
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
//qsort(配列名, 配列の数, 配列一つのバイト数, 比較関数)
|
162
|
-
|
163
|
-
qsort( plst, *count, sizeof(BEST_TEN*), cmpptr );
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
printf("\n過去のbestten\n-------------------------- \n");
|
170
|
-
|
171
|
-
// 並べ替え後の内容を表示
|
172
|
-
|
173
|
-
for(i=0;i<10;i++){
|
174
|
-
|
175
|
-
|
97
|
+
printf( "%d年 %d月 %d日 %d時 %d分 %d秒 \n",
|
98
|
+
|
176
|
-
|
99
|
+
score_data->time.tm_year + 1900,
|
100
|
+
|
101
|
+
score_data->time.tm_mon + 1,
|
102
|
+
|
177
|
-
|
103
|
+
score_data->time.tm_mday,
|
104
|
+
|
178
|
-
|
105
|
+
score_data->time.tm_hour,
|
106
|
+
|
107
|
+
score_data->time.tm_min,
|
108
|
+
|
179
|
-
|
109
|
+
score_data->time.tm_sec );
|
180
|
-
|
110
|
+
|
111
|
+
|
112
|
+
|
181
|
-
|
113
|
+
printf("得点(所要時間)は %.1f秒です。\n\n",
|
114
|
+
|
115
|
+
score_data->score );
|
116
|
+
|
117
|
+
|
182
118
|
|
183
119
|
}
|
184
120
|
|
185
|
-
bestscore=plst[0]->score;
|
186
|
-
|
187
|
-
fflush(stdout);
|
188
|
-
|
189
|
-
fclose(fp);
|
121
|
+
fclose(fp);
|
190
|
-
|
191
|
-
|
122
|
+
|
192
|
-
|
193
|
-
return bestscore;
|
194
|
-
|
195
|
-
}
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
|
196
|
-
|
127
|
+
double get_score(SCORE_DATA *score_data) {
|
128
|
+
|
197
|
-
|
129
|
+
return score_data->score;
|
130
|
+
|
131
|
+
}
|
198
132
|
|
199
133
|
|
200
134
|
|
@@ -202,53 +136,31 @@
|
|
202
136
|
|
203
137
|
{
|
204
138
|
|
205
|
-
int count=0; //
|
206
|
-
|
207
|
-
double score; // 今回の所要時間
|
208
|
-
|
209
|
-
double bestscore; // 最短所要時間
|
210
|
-
|
211
|
-
double jikan; // 時間
|
212
|
-
|
213
|
-
|
139
|
+
FILE *fp;
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
140
|
+
|
218
|
-
|
219
|
-
|
141
|
+
|
220
|
-
|
221
|
-
|
142
|
+
|
222
|
-
|
223
|
-
bestscore= get_data(&count); // get_data()で前回までの最短所要時間を
|
224
|
-
|
225
|
-
// ファイルから読み込んでbestscoreに代入する。
|
226
|
-
|
227
|
-
printf("bestscoreは%.1f\n\n", bestscore);
|
228
|
-
|
229
|
-
|
143
|
+
fp = fopen(dtfile, "rb");
|
144
|
+
|
145
|
+
|
146
|
+
|
230
|
-
|
147
|
+
print_score_data(score_data);
|
231
|
-
|
232
|
-
|
148
|
+
|
149
|
+
|
150
|
+
|
233
|
-
|
151
|
+
return 0;
|
234
|
-
|
235
|
-
|
236
|
-
|
152
|
+
|
237
|
-
}
|
153
|
+
}
|
154
|
+
|
238
|
-
|
155
|
+
```
|
239
|
-
|
240
156
|
|
241
157
|
/*
|
242
158
|
|
243
|
-
|
244
|
-
|
245
|
-
C:\MinGW\users\chap09\kadai>gcc -I. -o kadai9-1-
|
159
|
+
C:\MinGW\users\chap09\kadai>gcc -I. -o kadai9-1-7 kadai9-1-7.c pdcurses.a
|
246
|
-
|
247
|
-
|
160
|
+
|
248
|
-
|
249
|
-
|
250
|
-
|
161
|
+
|
162
|
+
|
251
|
-
C:\MinGW\users\chap09\kadai>kadai9-1-
|
163
|
+
C:\MinGW\users\chap09\kadai> kadai9-1-7
|
252
164
|
|
253
165
|
|
254
166
|
|
@@ -268,108 +180,44 @@
|
|
268
180
|
|
269
181
|
|
270
182
|
|
271
|
-
途中省略
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
2017年 9月 9日 12時 38分 12秒
|
276
|
-
|
277
|
-
得点(所要時間)は 8.0秒です。
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
2016年 1月
|
183
|
+
2016年 1月 4日 19時 16分 8秒
|
282
|
-
|
184
|
+
|
283
|
-
得点(所要時間)は
|
185
|
+
得点(所要時間)は9.0秒
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
186
|
+
|
288
|
-
|
289
|
-
|
187
|
+
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
188
|
+
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
bestscoreは6.0
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
過去のbestten
|
302
|
-
|
303
|
-
--------------------------
|
304
|
-
|
305
|
-
2017年 8月 14日 20時 57分 40秒
|
306
|
-
|
307
|
-
得点(所要時間)は 6.0秒です。
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
201
|
189
|
+
2016年 1月 4日 19時 16分 39秒
|
312
|
-
|
190
|
+
|
313
|
-
得点(所要時間)は
|
191
|
+
得点(所要時間)は10.0秒
|
314
|
-
|
315
|
-
|
316
|
-
|
192
|
+
|
193
|
+
|
194
|
+
|
317
|
-
2016年
|
195
|
+
2016年 1月 4日 19時 19分 7秒
|
318
|
-
|
196
|
+
|
319
|
-
得点(所要時間)は
|
197
|
+
得点(所要時間)は10.0秒
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
198
|
+
|
324
|
-
|
325
|
-
|
199
|
+
|
326
|
-
|
327
|
-
|
328
|
-
|
200
|
+
|
329
|
-
2016年 1月 4日 19時 1
|
201
|
+
2016年 1月 4日 19時 21分 11秒
|
330
|
-
|
202
|
+
|
331
|
-
得点(所要時間)は
|
203
|
+
得点(所要時間)は10.0秒
|
332
204
|
|
333
205
|
|
334
206
|
|
335
207
|
2016年 1月 4日 19時 21分 44秒
|
336
208
|
|
337
|
-
得点(所要時間)は
|
209
|
+
得点(所要時間)は8.0秒
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
210
|
+
|
342
|
-
|
343
|
-
|
211
|
+
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
212
|
+
|
348
|
-
|
349
|
-
得点(所要時間)は 8.0秒です。
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
2016年 1月 31日 21時 12分 13秒
|
354
|
-
|
355
|
-
得点(所要時間)は 8.0秒です。
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
201
|
213
|
+
2016年 1月 4日 19時 22分 55秒
|
360
|
-
|
214
|
+
|
361
|
-
得点(所要時間)は
|
215
|
+
得点(所要時間)は13.0秒
|
362
|
-
|
363
|
-
|
364
|
-
|
216
|
+
|
217
|
+
|
218
|
+
|
365
|
-
|
219
|
+
省略
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
220
|
+
|
370
|
-
|
371
|
-
|
221
|
+
|
372
222
|
|
373
223
|
*/
|
374
|
-
|
375
|
-
```
|
4
説明文の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
```c言語
|
2
2
|
|
3
|
+
以下のコードを実行して、過去のデータの中のベスト10を表示したいのですが、
|
4
|
+
|
5
|
+
大体そのとおりなのですが、完全でありません。どこを直せばいいでしょうか。
|
6
|
+
|
3
7
|
コード
|
4
8
|
|
5
9
|
/* ラックナンバーサーチ・トレーニング(最近の10回の日時)*/
|
3
全体のコードの修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
端末の実行画面
|
1
|
+
過去のbestten を表示したいが端末の実行画面が少しおかしい。
|
test
CHANGED
@@ -1,599 +1,371 @@
|
|
1
|
+
```c言語
|
2
|
+
|
3
|
+
コード
|
4
|
+
|
5
|
+
/* ラックナンバーサーチ・トレーニング(最近の10回の日時)*/
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
#include <stdio.h>
|
10
|
+
|
11
|
+
#include <time.h>
|
12
|
+
|
13
|
+
#include <float.h>
|
14
|
+
|
15
|
+
#include <ctype.h>
|
16
|
+
|
17
|
+
#include <stdlib.h>
|
18
|
+
|
19
|
+
#include <sys/types.h>
|
20
|
+
|
21
|
+
#include <unistd.h>
|
22
|
+
|
23
|
+
#include "getputch.h"
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
#define MAX_STAGE 3
|
28
|
+
|
29
|
+
#define swap(type, x, y) do { type t = x; x = y; y = t; } while (0)
|
30
|
+
|
31
|
+
#define MAX_NUM 10
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
char dtfile[] = "LACKNUM.DAT";
|
36
|
+
|
37
|
+
char dtfile2[] = "LACKNUM2.DAT";/* 最高記録用のファイル */
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
typedef struct {
|
42
|
+
|
43
|
+
int tm_year;
|
44
|
+
|
45
|
+
int tm_mon;
|
46
|
+
|
47
|
+
int tm_mday;
|
48
|
+
|
49
|
+
int tm_hour;
|
50
|
+
|
51
|
+
int tm_min;
|
52
|
+
|
53
|
+
int tm_sec;
|
54
|
+
|
55
|
+
double score;
|
56
|
+
|
57
|
+
} BEST_TEN;
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
// --------------- 比較用の関数 cmp -------------------
|
62
|
+
|
63
|
+
int cmpptr( const void *p, const void *q ) {
|
64
|
+
|
65
|
+
return (*(BEST_TEN**)p)->score - (*(BEST_TEN**)q)->score;
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
// ----------------------------------------------------
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
/*--- 過去のトレーニング情報を取得・表示して最高得点を返す ---*/
|
74
|
+
|
75
|
+
double get_data(int *count)
|
76
|
+
|
77
|
+
{
|
78
|
+
|
79
|
+
FILE *fp; // これまでの履歴を指すポインタ
|
80
|
+
|
81
|
+
FILE *fp2; // これまでの最短所要時間を指すポインタ
|
82
|
+
|
83
|
+
double score; //これまでの履歴の所要時間
|
84
|
+
|
85
|
+
double bestscore; //これまでの最短所要時間
|
86
|
+
|
87
|
+
int i,j=0;
|
88
|
+
|
89
|
+
BEST_TEN best_ten[100]={0};
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
if ((fp = fopen(dtfile, "rb")) == NULL) {
|
94
|
+
|
95
|
+
printf("ファイルを作成します。\n\n");
|
96
|
+
|
97
|
+
bestscore = DBL_MAX; /* float.hに定義されている。double型で表現できる最大値を表すマクロDBL_MAX */
|
98
|
+
|
99
|
+
} else {
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
struct tm local;
|
104
|
+
|
105
|
+
double line[256];
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
printf("\n過去の履歴\n-------------------------- \n");
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
while((i = fread(&local, sizeof(struct tm), 1, fp)) > 0 ){
|
114
|
+
|
115
|
+
printf("%d年 %d月 %d日 %d時 %d分 %d秒\n",
|
116
|
+
|
117
|
+
local.tm_year + 1900, local.tm_mon + 1,
|
118
|
+
|
119
|
+
local.tm_mday, local.tm_hour, local.tm_min, local.tm_sec);
|
120
|
+
|
121
|
+
fread(&score, sizeof(double), 1, fp);
|
122
|
+
|
123
|
+
printf("得点(所要時間)は%.1f秒\n\n", score);
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
best_ten[j].tm_year=local.tm_year;
|
128
|
+
|
129
|
+
best_ten[j].tm_mon=local.tm_mon;
|
130
|
+
|
131
|
+
best_ten[j].tm_mday=local.tm_mday;
|
132
|
+
|
133
|
+
best_ten[j].tm_hour=local.tm_hour;
|
134
|
+
|
135
|
+
best_ten[j].tm_min=local.tm_min;
|
136
|
+
|
137
|
+
best_ten[j].tm_sec=local.tm_sec;
|
138
|
+
|
139
|
+
best_ten[j].score=score;
|
140
|
+
|
141
|
+
j++;
|
142
|
+
|
143
|
+
(*count)++;
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
printf("count1は%d\n\n", *count);
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
BEST_TEN *plst[*count];
|
152
|
+
|
153
|
+
for( i = 0; i < *count; i++ ) plst[i] = &best_ten[i];
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
//qsort(配列名, 配列の数, 配列一つのバイト数, 比較関数)
|
158
|
+
|
159
|
+
qsort( plst, *count, sizeof(BEST_TEN*), cmpptr );
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
printf("\n過去のbestten\n-------------------------- \n");
|
166
|
+
|
167
|
+
// 並べ替え後の内容を表示
|
168
|
+
|
169
|
+
for(i=0;i<10;i++){
|
170
|
+
|
171
|
+
printf( "%d年 %d月 %d日 %d時 %d分 %d秒 \n"
|
172
|
+
|
173
|
+
,plst[i]->tm_year+1900, plst[i]->tm_mon+1, plst[i]->tm_mday,
|
174
|
+
|
175
|
+
plst[i]->tm_hour,plst[i]->tm_min,plst[i]->tm_sec );
|
176
|
+
|
177
|
+
printf("得点(所要時間)は %.1f秒です。\n\n", plst[i]->score);
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
bestscore=plst[0]->score;
|
182
|
+
|
183
|
+
fflush(stdout);
|
184
|
+
|
185
|
+
fclose(fp);
|
186
|
+
|
187
|
+
printf("count2は%d\n\n", *count);
|
188
|
+
|
189
|
+
return bestscore;
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
int main(void)
|
198
|
+
|
199
|
+
{
|
200
|
+
|
201
|
+
int count=0; //
|
202
|
+
|
203
|
+
double score; // 今回の所要時間
|
204
|
+
|
205
|
+
double bestscore; // 最短所要時間
|
206
|
+
|
207
|
+
double jikan; // 時間
|
208
|
+
|
209
|
+
FILE *fp;
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
struct tm local ;
|
214
|
+
|
215
|
+
int k;
|
216
|
+
|
217
|
+
int i, j, x, stage;
|
218
|
+
|
219
|
+
bestscore= get_data(&count); // get_data()で前回までの最短所要時間を
|
220
|
+
|
221
|
+
// ファイルから読み込んでbestscoreに代入する。
|
222
|
+
|
223
|
+
printf("bestscoreは%.1f\n\n", bestscore);
|
224
|
+
|
225
|
+
printf("count3は%d\n\n", count);
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
return 0;
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
/*
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
C:\MinGW\users\chap09\kadai>gcc -I. -o kadai9-1-5 kadai9-1-5.c pdcurs
|
242
|
+
|
243
|
+
es.a
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
C:\MinGW\users\chap09\kadai>kadai9-1-5
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
過去の履歴
|
252
|
+
|
253
|
+
--------------------------
|
254
|
+
|
255
|
+
2015年 10月 27日 19時 9分 59秒
|
256
|
+
|
257
|
+
得点(所要時間)は11.0秒
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
2016年 1月 4日 19時 15分 11秒
|
262
|
+
|
263
|
+
得点(所要時間)は8.0秒
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
途中省略
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
2017年 9月 9日 12時 38分 12秒
|
272
|
+
|
273
|
+
得点(所要時間)は 8.0秒です。
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
2016年 1月 31日 21時 12分 13秒
|
278
|
+
|
279
|
+
得点(所要時間)は 8.0秒です。
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
2017年 9月 9日 11時 28分 59秒
|
284
|
+
|
285
|
+
得点(所要時間)は 8.0秒です。
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
count2は66
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
bestscoreは6.0
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
過去のbestten
|
298
|
+
|
299
|
+
--------------------------
|
300
|
+
|
301
|
+
2017年 8月 14日 20時 57分 40秒
|
302
|
+
|
303
|
+
得点(所要時間)は 6.0秒です。
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
2017年 9月 9日 12時 14分 36秒
|
308
|
+
|
309
|
+
得点(所要時間)は 6.2秒です。
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
2016年 5月 2日 17時 0分 48秒
|
314
|
+
|
315
|
+
得点(所要時間)は 7.0秒です。
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
2017年 9月 9日 12時 3分 5秒
|
320
|
+
|
321
|
+
得点(所要時間)は 6.1秒です。
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
2016年 1月 4日 19時 15分 11秒
|
326
|
+
|
327
|
+
得点(所要時間)は 8.0秒です。
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
2016年 1月 4日 19時 21分 44秒
|
332
|
+
|
333
|
+
得点(所要時間)は 8.0秒です。
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
2017年 9月 9日 12時 4分 2秒
|
338
|
+
|
339
|
+
得点(所要時間)は 7.5秒です。
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
2017年 9月 9日 12時 38分 12秒
|
344
|
+
|
345
|
+
得点(所要時間)は 8.0秒です。
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
2016年 1月 31日 21時 12分 13秒
|
350
|
+
|
351
|
+
得点(所要時間)は 8.0秒です。
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
2017年 9月 9日 11時 28分 59秒
|
356
|
+
|
357
|
+
得点(所要時間)は 8.0秒です。
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
count2は66
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
bestscoreは6.0
|
366
|
+
|
367
|
+
C:\MinGW\users\chap09\kadai>
|
368
|
+
|
369
|
+
*/
|
370
|
+
|
1
371
|
```
|
2
|
-
|
3
|
-
以下を実行すると端末画面に”欠けている数字を入力してください。
|
4
|
-
|
5
|
-
スペースキーで開始します。”
|
6
|
-
|
7
|
-
の下に訳の分からない文字と、選んだラックナンバーサーチの番号が表示されるのですが
|
8
|
-
|
9
|
-
これを実行画面にでないようにしたい。関係しているのはmainの
|
10
|
-
|
11
|
-
printfprintf("1. ラックナンバ \n");と printf("2. ダブルナンバリサーチ \n");
|
12
|
-
|
13
|
-
printf("どのゲームを行いますか。番号を入力してください ==> ");
|
14
|
-
|
15
|
-
scanf("%d", &bango);です。ラックナンバ リサーチをラックナンバリサにすると消えますが。
|
16
|
-
|
17
|
-
前はダブルナンバリサーチのチが表示されていました。今はよくわからない文字が表示されます。
|
18
|
-
|
19
|
-
そのあとに選んだラックナンバーサーチの番号が表示されるのです(1とか2とか)
|
20
|
-
|
21
|
-
関数goと関数mainを直すところがあれば教えてください。
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
コード
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
// ラックナンバーサーチ・トレーニング(最近の10回の日時)
|
32
|
-
|
33
|
-
#include <stdio.h>
|
34
|
-
|
35
|
-
#include <time.h>
|
36
|
-
|
37
|
-
#include <float.h>
|
38
|
-
|
39
|
-
#include <ctype.h>
|
40
|
-
|
41
|
-
#include <stdlib.h>
|
42
|
-
|
43
|
-
#include <sys/types.h>
|
44
|
-
|
45
|
-
#include <unistd.h>
|
46
|
-
|
47
|
-
#include "getputch.h"
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
#define MAX_STAGE 3
|
52
|
-
|
53
|
-
#define swap(type, x, y) do { type t = x; x = y; y = t; } while (0)
|
54
|
-
|
55
|
-
#define MAX_NUM 10
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
char dtfile[] = "LACKNUM.DAT";
|
60
|
-
|
61
|
-
char dtfile2[] = "LACKNUM2.DAT";/* 最高記録用のファイル */
|
62
|
-
|
63
|
-
double score2;
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
typedef struct {
|
68
|
-
|
69
|
-
int tm_year;
|
70
|
-
|
71
|
-
int tm_mon;
|
72
|
-
|
73
|
-
int tm_mday;
|
74
|
-
|
75
|
-
int tm_hour;
|
76
|
-
|
77
|
-
int tm_min;
|
78
|
-
|
79
|
-
int tm_sec;
|
80
|
-
|
81
|
-
double best;
|
82
|
-
|
83
|
-
} BEST_TEN;
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
// 比較用の関数 cmp
|
88
|
-
|
89
|
-
int cmpptr( const void *p, const void *q ) {
|
90
|
-
|
91
|
-
return (*(BEST_TEN**)p)->best - (*(BEST_TEN**)q)->best;
|
92
|
-
|
93
|
-
}
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
//1回実行したとき進むポイントの大きさを求める
|
98
|
-
|
99
|
-
int kaime_p(fpos_t* kaime_p1)
|
100
|
-
|
101
|
-
{
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
省略
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
}
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
//local のデータを新しい順にならべる。
|
114
|
-
|
115
|
-
void new_local_data(fpos_t ft,int k)
|
116
|
-
|
117
|
-
{
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
省略
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
}
|
126
|
-
|
127
|
-
//過去のトレーニング情報を取得・表示して最高得点を返す
|
128
|
-
|
129
|
-
double get_data(int *count)
|
130
|
-
|
131
|
-
{
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
省略
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
}
|
140
|
-
|
141
|
-
//今回のトレーニング情報を書き込む
|
142
|
-
|
143
|
-
void put_data(double best, double best2)
|
144
|
-
|
145
|
-
{
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
省略
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
}
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
//トレーニングを実行して得点(所要時間)を返す
|
158
|
-
|
159
|
-
double go(void)
|
160
|
-
|
161
|
-
{
|
162
|
-
|
163
|
-
int i, j, stage;
|
164
|
-
|
165
|
-
int dgt[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
|
166
|
-
|
167
|
-
int a[8];
|
168
|
-
|
169
|
-
double jikan;
|
170
|
-
|
171
|
-
clock_t start, end;
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
printf("\n欠けている数字を入力してください。\n");
|
176
|
-
|
177
|
-
printf("スペースキーで開始します。\n");
|
178
|
-
|
179
|
-
while (getch() != ' ')
|
180
|
-
|
181
|
-
;
|
182
|
-
|
183
|
-
start = time(NULL);
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
for (stage = 0; stage < MAX_STAGE; stage++) {
|
188
|
-
|
189
|
-
int x = rand() % 9;
|
190
|
-
|
191
|
-
int no; // 読み込んだ値
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
i = j = 0;
|
196
|
-
|
197
|
-
while (i < 9) { // dgt[x]を飛ばしてコピー
|
198
|
-
|
199
|
-
if (i != x)
|
200
|
-
|
201
|
-
a[j++] = dgt[i];// dgt[x]は1から9までの数字が入っている配列
|
202
|
-
|
203
|
-
i++;
|
204
|
-
|
205
|
-
}
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
for (i = 7; i > 0; i--) { // 配列aをシャッフル、配列の添字は0から7までの8個である
|
210
|
-
|
211
|
-
int j = rand() % (i + 1);
|
212
|
-
|
213
|
-
if (i != j)
|
214
|
-
|
215
|
-
swap(int, a[i], a[j]);
|
216
|
-
|
217
|
-
}
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
printf("%d回目:", stage+1);
|
222
|
-
|
223
|
-
for (i = 0; i < 8; i++){ // 全要素を表示
|
224
|
-
|
225
|
-
printf("%d ", a[i]);
|
226
|
-
|
227
|
-
}
|
228
|
-
|
229
|
-
printf(":");
|
230
|
-
|
231
|
-
fflush(stdout);
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
do {
|
236
|
-
|
237
|
-
no = getch();
|
238
|
-
|
239
|
-
if (isprint(no)) {
|
240
|
-
|
241
|
-
putch(no);
|
242
|
-
|
243
|
-
if (no != dgt[x] + '0')
|
244
|
-
|
245
|
-
putch('\b');
|
246
|
-
|
247
|
-
else
|
248
|
-
|
249
|
-
printf("\n");
|
250
|
-
|
251
|
-
}
|
252
|
-
|
253
|
-
} while (no != dgt[x] + '0');
|
254
|
-
|
255
|
-
}
|
256
|
-
|
257
|
-
end = time(NULL);
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
jikan = (double)difftime(end, start);
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
printf("%.1f秒かかりました。\n", jikan);
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
if (jikan > 25.0)
|
270
|
-
|
271
|
-
printf("鈍すぎます。\n");
|
272
|
-
|
273
|
-
else if (jikan > 20.0)
|
274
|
-
|
275
|
-
printf("少し鈍いですね。\n");
|
276
|
-
|
277
|
-
else if (jikan > 17.0)
|
278
|
-
|
279
|
-
printf("まあまあですね。\n");
|
280
|
-
|
281
|
-
else
|
282
|
-
|
283
|
-
printf("素早いですね。\n");
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
return (jikan);
|
288
|
-
|
289
|
-
}
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
int main(void)
|
294
|
-
|
295
|
-
{
|
296
|
-
|
297
|
-
int retry,count=0;
|
298
|
-
|
299
|
-
double score; // 今回の所要時間
|
300
|
-
|
301
|
-
double best; // 最短所要時間
|
302
|
-
|
303
|
-
double jikan;
|
304
|
-
|
305
|
-
FILE *fp;
|
306
|
-
|
307
|
-
fpos_t ft;
|
308
|
-
|
309
|
-
fpos_t kaime_p1;
|
310
|
-
|
311
|
-
struct tm local ;
|
312
|
-
|
313
|
-
int k,bango;
|
314
|
-
|
315
|
-
int i, j, x, stage;
|
316
|
-
|
317
|
-
int dgt[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
|
318
|
-
|
319
|
-
int a[10];
|
320
|
-
|
321
|
-
int no; // 読み込んだ値
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
clock_t start, end;
|
326
|
-
|
327
|
-
best= get_data(&count);
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
printf("bestは%d\n\n", best);
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
fp = fopen(dtfile, "rb");
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
kaime_p(&kaime_p1);
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
k=kaime_p1;
|
344
|
-
|
345
|
-
//ファイルポインタの位置を取得
|
346
|
-
|
347
|
-
printf("mainのkaime_p(&kaime_p1)後のkの値は「%d」です。\n\n",k);
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
//ファイルポインタを末尾まで移動
|
352
|
-
|
353
|
-
fseek(fp,0,SEEK_END);
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
//ファイルポインタの位置を取得
|
358
|
-
|
359
|
-
fgetpos(fp,&ft); //ファイルfpの現在のファイル位置を取得して
|
360
|
-
|
361
|
-
// &ftの示す場所に格納します。
|
362
|
-
|
363
|
-
new_local_data(ft,k);
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
fgetpos(fp,&ft);
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
printf("1. ラックナンバ \n");
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
printf("2. ダブルナンバリサーチ \n");
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
printf("どのゲームを行いますか。番号を入力してください ==> ");
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
scanf("%d", &bango);
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
switch (bango)
|
392
|
-
|
393
|
-
{
|
394
|
-
|
395
|
-
case 1: //ラックナンバーリサーチ
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
init_getputch(); //ライブラリの初期処理235p、initscr(),cbreak(),noecho(),refresh()
|
400
|
-
|
401
|
-
srand(time(NULL));
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
do {
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
score = go(); // トレーニング(go)で実行、返却された所要時間(jika)をscoreに代入する。
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
if (score < best) {
|
414
|
-
|
415
|
-
printf("最短所要時間を更新しました!!\n");
|
416
|
-
|
417
|
-
best = score; /* 最高得点更新 */
|
418
|
-
|
419
|
-
}
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
printf("もう一度しますか … (0)いいえ (1)はい:");
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
scanf("%d", &retry);
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
} while (retry == 1);
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
put_data(score,best); // 今回の日付・時刻・得点を書き込む
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
fclose(fp);
|
440
|
-
|
441
|
-
fflush(stdout);
|
442
|
-
|
443
|
-
term_getputch();
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
break;
|
448
|
-
|
449
|
-
case 2: //ダブルナンバーリサーチ
|
450
|
-
|
451
|
-
init_getputch();
|
452
|
-
|
453
|
-
srand(time(NULL));
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
printf("\nダブっている数字を入力してください\n");
|
458
|
-
|
459
|
-
printf("スペースキーで開始します\n");
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
while (getch() != ' ')
|
464
|
-
|
465
|
-
;
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
start = clock();
|
470
|
-
|
471
|
-
for (stage = 0; stage < MAX_STAGE; stage++) {
|
472
|
-
|
473
|
-
x = rand() % 9;
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
i = j = 0;
|
478
|
-
|
479
|
-
while (i < 9) { // dgt[x]をダブらせてコピー
|
480
|
-
|
481
|
-
a[j++] = dgt[i];
|
482
|
-
|
483
|
-
if (i == x)
|
484
|
-
|
485
|
-
a[j++] = dgt[i];
|
486
|
-
|
487
|
-
i++;
|
488
|
-
|
489
|
-
}
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
for (i = 9; i > 0; i--) { // 配列aをシャッフル
|
494
|
-
|
495
|
-
int j = rand() % (i + 1);
|
496
|
-
|
497
|
-
if (i != j)
|
498
|
-
|
499
|
-
swap(int, a[i], a[j]);
|
500
|
-
|
501
|
-
}
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
for (i = 0; i < 10; i++) // 全要素を表示
|
506
|
-
|
507
|
-
printf("%d ", a[i]);
|
508
|
-
|
509
|
-
printf(":");
|
510
|
-
|
511
|
-
fflush(stdout);
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
do {
|
516
|
-
|
517
|
-
no = getch();
|
518
|
-
|
519
|
-
if (isprint(no)) {
|
520
|
-
|
521
|
-
putch(no);
|
522
|
-
|
523
|
-
if (no != dgt[x] + '0')
|
524
|
-
|
525
|
-
putch('\b');
|
526
|
-
|
527
|
-
else
|
528
|
-
|
529
|
-
printf("\n");
|
530
|
-
|
531
|
-
}
|
532
|
-
|
533
|
-
} while (no != dgt[x] + '0');
|
534
|
-
|
535
|
-
}
|
536
|
-
|
537
|
-
end = clock();
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
jikan = (double)(end - start) / CLOCKS_PER_SEC;
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
printf("%.1f秒かかりました\n", jikan);
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
if (jikan > 25.0)
|
550
|
-
|
551
|
-
printf("鈍すぎます\n");
|
552
|
-
|
553
|
-
else if (jikan > 20.0)
|
554
|
-
|
555
|
-
printf("少し鈍いですね\n");
|
556
|
-
|
557
|
-
else if (jikan > 17.0)
|
558
|
-
|
559
|
-
printf("まあまあですね\n");
|
560
|
-
|
561
|
-
else
|
562
|
-
|
563
|
-
printf("素早いですね\n");
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
term_getputch();
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
break;
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
default:
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
printf("番号が不当です\n");
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
}
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
return 0;
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
}
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
```
|
2
説明文の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,11 +12,11 @@
|
|
12
12
|
|
13
13
|
printf("どのゲームを行いますか。番号を入力してください ==> ");
|
14
14
|
|
15
|
-
scanf("%d", &bango);です。ラックナンバ リサーチをラックナンバにすると消えますが。
|
15
|
+
scanf("%d", &bango);です。ラックナンバ リサーチをラックナンバリサにすると消えますが。
|
16
|
-
|
16
|
+
|
17
|
-
前はダブルナンバリサーチのチが表示されていました。今はよくわからない
|
17
|
+
前はダブルナンバリサーチのチが表示されていました。今はよくわからない文字が表示されます。
|
18
|
-
|
18
|
+
|
19
|
-
そのあとに選んだラックナンバーサーチの番号が表示されるのです
|
19
|
+
そのあとに選んだラックナンバーサーチの番号が表示されるのです(1とか2とか)
|
20
20
|
|
21
21
|
関数goと関数mainを直すところがあれば教えてください。
|
22
22
|
|
1
タグの変更
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|