質問編集履歴
3
コードを入れ替えしました
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,30 +1,330 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
ラックナンバー
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
1
|
+
```c
|
2
|
+
|
3
|
+
//ラックナンバーサーチ・トレーニングでベストテンを選び出すフローチャート
|
4
|
+
|
5
|
+
以下のように変更しましたが、うまくいきません。おしえてください。お願いします。
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
// 1, ラックナンバーサーチ・トレーニングで実行した日付と実行時間が
|
10
|
+
|
11
|
+
// char dtfile[] = "LACKNUM.DAT" に入っている
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
// 2, 並べ替え前の"LACKNUM.DAT"を表示する。
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
// 3, truct tm localとdouble bestの要素を持つ構造体を定義する。
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
// 4, LACKNUM.DATに保存されているデータを記録するのに
|
24
|
+
|
25
|
+
// 十分な数の配列dtfile2を確保。
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
// 5, その配列へget_data()関数にて読み込んで下さい。
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
// 6, LACKNUM.DATに保存されているデータを並べ替えて表示する
|
38
|
+
|
39
|
+
// を確保して下さい。
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
// 7, "LACKNUM.DAT"を"best"の小さい順に並べ替えて
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
// 8, "LACKNUM2.DAT"を表示する。
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
// ラックナンバーサーチ・トレーニング(1部です。必要ないところもあります)
|
54
|
+
|
55
|
+
#include <stdio.h>
|
56
|
+
|
57
|
+
#include <time.h>
|
58
|
+
|
59
|
+
#include <float.h>
|
60
|
+
|
61
|
+
#include <ctype.h>
|
62
|
+
|
63
|
+
#include <stdlib.h>
|
64
|
+
|
65
|
+
#include <sys/types.h>
|
66
|
+
|
67
|
+
#include <unistd.h>
|
68
|
+
|
69
|
+
#include "getputch.h"
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
#define MAX_STAGE 3
|
74
|
+
|
75
|
+
#define swap(type, x, y) do { type t = x; x = y; y = t; } while (0)
|
76
|
+
|
77
|
+
#define MAX_NUM 10
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
char dtfile[100] = "LACKNUM.DAT"; // 元のファイル名
|
82
|
+
|
83
|
+
char dtfile2[100] = "LACKNUM2.DAT"; // 実行時間順に並べたファイル名
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
typedef struct {
|
88
|
+
|
89
|
+
struct tm local;
|
90
|
+
|
91
|
+
double best;
|
92
|
+
|
93
|
+
}time_besten;
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
//ソートしたい配列の要素番号列を保存し,実際にソートされる配列
|
98
|
+
|
99
|
+
//動的に確保される
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
//"LACKNUM.DAT"を "LACKNUM2.DAT"にコピーする。bcopyでコピーする
|
104
|
+
|
105
|
+
// その配列へget_data()関数にて読み込んで下さい。
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
double get_data1(void){
|
112
|
+
|
113
|
+
int i;
|
114
|
+
|
115
|
+
FILE *fp;
|
116
|
+
|
117
|
+
double best;
|
118
|
+
|
119
|
+
char title[256];
|
120
|
+
|
121
|
+
puts(title);
|
122
|
+
|
123
|
+
//int puts(char * s);
|
124
|
+
|
125
|
+
//puts 関数は標準出力に s が指す文字列を書き込みます.
|
126
|
+
|
127
|
+
//(出力の最後に自動的に改行文字を追加します.)
|
128
|
+
|
129
|
+
//文字列の終端ナル
|
130
|
+
|
131
|
+
if ((fp = fopen(dtfile, "rb")) == NULL) {
|
132
|
+
|
133
|
+
printf("ファイルを作成します。\n\n");
|
134
|
+
|
135
|
+
best = DBL_MAX; /* float.hに定義されている。double型で表現できる最大値を表すマクロDBL_MAX */
|
136
|
+
|
137
|
+
}else {
|
138
|
+
|
139
|
+
int i;
|
140
|
+
|
141
|
+
struct tm local;
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
while((i = fread(&local, sizeof(struct tm), 1, fp)) > 0 ){
|
146
|
+
|
147
|
+
printf("%d年 %d月 %d日 %d時 %d分 %d秒\n",
|
148
|
+
|
149
|
+
local.tm_year + 1900, local.tm_mon + 1,
|
150
|
+
|
151
|
+
local.tm_mday, local.tm_hour, local.tm_min, local.tm_sec);
|
152
|
+
|
153
|
+
fread(&best, sizeof(double), 1, fp);
|
154
|
+
|
155
|
+
printf("得点(所要時間)は%.1f秒\n\n", best);
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
fclose(fp);
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
printf("\n");
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
double get_data2(void)
|
170
|
+
|
171
|
+
{
|
172
|
+
|
173
|
+
int i;
|
174
|
+
|
175
|
+
FILE *fp2;
|
176
|
+
|
177
|
+
double best2;
|
178
|
+
|
179
|
+
char title[256];
|
180
|
+
|
181
|
+
puts(title);
|
182
|
+
|
183
|
+
//int puts(char * s);
|
184
|
+
|
185
|
+
//puts 関数は標準出力に s が指す文字列を書き込みます.
|
186
|
+
|
187
|
+
//(出力の最後に自動的に改行文字を追加します.)
|
188
|
+
|
189
|
+
//文字列の終端ナル
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
if ((fp2 = fopen(dtfile2, "rb")) == NULL) {
|
194
|
+
|
195
|
+
printf("ファイルを作成します。\n\n");
|
196
|
+
|
197
|
+
best2 = DBL_MAX; /* float.hに定義されている。double型で表現できる最大値を表すマクロDBL_MAX */
|
198
|
+
|
199
|
+
} else {
|
200
|
+
|
201
|
+
int i;
|
202
|
+
|
203
|
+
struct tm local;
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
while((i = fread(&local, sizeof(struct tm), 1, fp2)) > 0 ){
|
208
|
+
|
209
|
+
printf("%d年 %d月 %d日 %d時 %d分 %d秒\n",
|
210
|
+
|
211
|
+
local.tm_year + 1900, local.tm_mon + 1,
|
212
|
+
|
213
|
+
local.tm_mday, local.tm_hour, local.tm_min, local.tm_sec);
|
214
|
+
|
215
|
+
fread(&best2, sizeof(double), 1, fp2);
|
216
|
+
|
217
|
+
printf("得点(所要時間)は%.1f秒\n\n", best2);
|
218
|
+
|
219
|
+
}
|
220
|
+
|
221
|
+
fclose(fp2);
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
printf("\n");
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
int compfuncBest(const void *a, const void *b)
|
234
|
+
|
235
|
+
{
|
236
|
+
|
237
|
+
double comp;
|
238
|
+
|
239
|
+
comp = ((time_besten*)a)->best - ((time_besten*)b)->best;
|
240
|
+
|
241
|
+
// time_besten型のポインタにキャストしてからメンバbestで比較
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
if (comp<0.) return -1;
|
246
|
+
|
247
|
+
else if (0.<comp) return 1;
|
248
|
+
|
249
|
+
else return 0;
|
250
|
+
|
251
|
+
}
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
int main(void)
|
256
|
+
|
257
|
+
{
|
258
|
+
|
259
|
+
int i,num;
|
260
|
+
|
261
|
+
FILE *fp; // *fpと *fp3はファイルポインタ
|
262
|
+
|
263
|
+
double best;
|
264
|
+
|
265
|
+
time_besten besten;//time_besten besten;を配列として定義する。
|
266
|
+
|
267
|
+
time_t t = time(NULL);
|
268
|
+
|
269
|
+
struct tm *local = localtime(&t);
|
270
|
+
|
271
|
+
int *index;
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
int DataSize=sizeof(int);
|
276
|
+
|
277
|
+
int NumberOfDatas=sizeof(dtfile2)/sizeof(time_besten);
|
278
|
+
|
279
|
+
printf("size of (int)= %d\n",sizeof(int));
|
280
|
+
|
281
|
+
printf("size of (double)= %d\n",sizeof(double));
|
282
|
+
|
283
|
+
printf("size of (time_besten)= %d\n",sizeof(time_besten));
|
284
|
+
|
285
|
+
printf("size of (struct tm)= %d\n",sizeof(struct tm));
|
286
|
+
|
287
|
+
printf("\n");
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
index=(int *)malloc(NumberOfDatas*sizeof(int));
|
292
|
+
|
293
|
+
for (i=0; i<NumberOfDatas; i++) index[i]=i;
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
get_data1();
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
qsort(index, NumberOfDatas, DataSize, compfuncBest);
|
302
|
+
|
303
|
+
get_data2();
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
free(index);
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
return 0;
|
312
|
+
|
313
|
+
}
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
/*
|
18
318
|
|
19
319
|
....@naka ~/besten
|
20
320
|
|
21
|
-
$ gcc -o best-fchart
|
321
|
+
$ gcc -o best-fchart7 best-fchart7.c -lpdcursesw
|
22
322
|
|
23
323
|
|
24
324
|
|
25
325
|
....@naka ~/besten
|
26
326
|
|
27
|
-
$ best-fchart
|
327
|
+
$ best-fchart5
|
28
328
|
|
29
329
|
初期状態
|
30
330
|
|
@@ -130,216 +430,8 @@
|
|
130
430
|
|
131
431
|
//並べ替えはquicksortを使う
|
132
432
|
|
133
|
-
//並べ替え後の"LACKNUM.DAT"を表示する。
|
433
|
+
//並べ替え後の"LACKNUM2.DAT"を表示する。
|
134
434
|
|
135
435
|
|
136
436
|
|
137
437
|
*/
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
###ソースコード
|
144
|
-
|
145
|
-
```
|
146
|
-
|
147
|
-
//ラックナンバーサーチ・トレーニングでベストテンを選び出すフローチャート
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
// 1, ラックナンバーサーチ・トレーニングで実行した日付と実行時間が
|
152
|
-
|
153
|
-
// char dtfile[] = "LACKNUM.DAT" (44バイト)に入っている
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
// 2, 並べ替え前の"LACKNUM.DAT"を表示する。
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
// 3, truct tm localとdouble bestの要素を持つ構造体を定義する。
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
// 4, LACKNUM.DATに保存されているデータを並べ替えて表示する
|
166
|
-
|
167
|
-
// を確保して下さい。
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
// 5, ソートはその次の段階となります。
|
172
|
-
|
173
|
-
// "LACKNUM.DAT"を"best"の小さい順に並べ替える(そのまま表示する。)
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
// 6, "LACKNUM.DAT"を表示する。
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
// ラックナンバーサーチ・トレーニング(1部です。必要ないところもあります)
|
184
|
-
|
185
|
-
#include <stdio.h>
|
186
|
-
|
187
|
-
#include <time.h>
|
188
|
-
|
189
|
-
#include <float.h>
|
190
|
-
|
191
|
-
#include <ctype.h>
|
192
|
-
|
193
|
-
#include <stdlib.h>
|
194
|
-
|
195
|
-
#include <sys/types.h>
|
196
|
-
|
197
|
-
#include <unistd.h>
|
198
|
-
|
199
|
-
#include "getputch.h"
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
#define MAX_STAGE 3
|
204
|
-
|
205
|
-
#define swap(type, x, y) do { type t = x; x = y; y = t; } while (0)
|
206
|
-
|
207
|
-
#define MAX_NUM 10
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
char dtfile[] = "LACKNUM.DAT"; // ファイル名
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
typedef struct {
|
216
|
-
|
217
|
-
struct tm local;
|
218
|
-
|
219
|
-
double best;
|
220
|
-
|
221
|
-
}time_besten;
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
void printData(time_besten data[], int num, char *title)
|
226
|
-
|
227
|
-
{
|
228
|
-
|
229
|
-
int i;
|
230
|
-
|
231
|
-
FILE *fp;
|
232
|
-
|
233
|
-
double best;
|
234
|
-
|
235
|
-
puts(title);
|
236
|
-
|
237
|
-
//int puts(char * s);
|
238
|
-
|
239
|
-
//puts 関数は標準出力に s が指す文字列を書き込みます.
|
240
|
-
|
241
|
-
//(出力の最後に自動的に改行文字を追加します.)
|
242
|
-
|
243
|
-
//文字列の終端ナル文字 ('\0') の書き込みは行いません.
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
if ((fp = fopen(dtfile, "rb")) == NULL) {
|
250
|
-
|
251
|
-
printf("ファイルを作成します。\n\n");
|
252
|
-
|
253
|
-
best = DBL_MAX; /* float.hに定義されている。double型で表現できる最大値を表すマクロDBL_MAX */
|
254
|
-
|
255
|
-
} else {
|
256
|
-
|
257
|
-
int i;
|
258
|
-
|
259
|
-
struct tm local;
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
while((i = fread(&local, sizeof(struct tm), 1, fp)) > 0 ){
|
264
|
-
|
265
|
-
printf("%d年 %d月 %d日 %d時 %d分 %d秒\n",
|
266
|
-
|
267
|
-
local.tm_year + 1900, local.tm_mon + 1,
|
268
|
-
|
269
|
-
local.tm_mday, local.tm_hour, local.tm_min, local.tm_sec);
|
270
|
-
|
271
|
-
fread(&best, sizeof(double), 1, fp);
|
272
|
-
|
273
|
-
printf("得点(所要時間)は%.1f秒\n\n", best);
|
274
|
-
|
275
|
-
}
|
276
|
-
|
277
|
-
fclose(fp);
|
278
|
-
|
279
|
-
}
|
280
|
-
|
281
|
-
printf("\n");
|
282
|
-
|
283
|
-
}
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
int compfuncBest(const void *a, const void *b)
|
288
|
-
|
289
|
-
{
|
290
|
-
|
291
|
-
double comp;
|
292
|
-
|
293
|
-
comp = ((time_besten*)a)->best - ((time_besten*)b)->best;
|
294
|
-
|
295
|
-
// time_besten型のポインタにキャストしてからメンバbestで比較
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
if (comp<0.) return -1;
|
300
|
-
|
301
|
-
else if (0.<comp) return 1;
|
302
|
-
|
303
|
-
else return 0;
|
304
|
-
|
305
|
-
}
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
int main(void)
|
310
|
-
|
311
|
-
{
|
312
|
-
|
313
|
-
int i,num;
|
314
|
-
|
315
|
-
FILE *fp; // *fpと *fp3はファイルポインタ
|
316
|
-
|
317
|
-
double best;
|
318
|
-
|
319
|
-
time_besten besten;
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
int DataSize=sizeof(time_besten);
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
int NumberOfDatas=sizeof(besten)/DataSize;
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
printData(&besten , NumberOfDatas, "初期状態");
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
qsort(&besten, NumberOfDatas, DataSize, compfuncBest);
|
338
|
-
|
339
|
-
printData(&besten, NumberOfDatas, "ベストテン");
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
return 0;
|
344
|
-
|
345
|
-
}
|
2
プログラム全体をなおしました
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ラックナンバーリサーチで
|
1
|
+
ラックナンバーリサーチで
|
test
CHANGED
@@ -4,43 +4,181 @@
|
|
4
4
|
|
5
5
|
struct time_bestenは定義すみです。
|
6
6
|
|
7
|
-
そのデータは"LACKNUM3.DAT"に格納したいです。
|
8
|
-
|
9
|
-
今回はとりあえず、"LACKNUM.DAT"から"LACKNUM3.DAT"にデータをコピーするプログラムを作り、コンパイル、
|
10
|
-
|
11
|
-
|
7
|
+
並び替えができていないみたいですが、
|
12
|
-
|
8
|
+
|
13
|
-
|
9
|
+
どこが悪いのかよくわかりません。
|
10
|
+
|
14
|
-
|
11
|
+
よろしくお願いします
|
15
|
-
|
16
|
-
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
-
###
|
17
|
+
###実行状況
|
18
|
-
|
18
|
+
|
19
|
-
..@naka ~/besten
|
19
|
+
....@naka ~/besten
|
20
|
-
|
20
|
+
|
21
|
-
$ gcc -o bc
|
21
|
+
$ gcc -o best-fchart3 best-fchart3.c -lpdcursesw
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
....@naka ~/besten
|
26
|
+
|
27
|
+
$ best-fchart3
|
28
|
+
|
29
|
+
初期状態
|
30
|
+
|
31
|
+
2015年 10月 27日 19時 9分 59秒
|
32
|
+
|
33
|
+
得点(所要時間)は11.0秒
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
2016年 1月 4日 19時 15分 11秒
|
38
|
+
|
39
|
+
得点(所要時間)は8.0秒
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
2016年 1月 4日 19時 16分 8秒
|
44
|
+
|
45
|
+
得点(所要時間)は9.0秒
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
2016年 1月 4日 19時 16分 39秒
|
50
|
+
|
51
|
+
得点(所要時間)は10.0秒
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
2016年 1月 4日 19時 19分 7秒
|
56
|
+
|
57
|
+
得点(所要時間)は10.0秒
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
2016年 1月 4日 19時 21分 11秒
|
62
|
+
|
63
|
+
得点(所要時間)は10.0秒
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
2016年 1月 4日 19時 21分 44秒
|
68
|
+
|
69
|
+
得点(所要時間)は8.0秒
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
ベストテン時間)は8.0秒
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
2015年 10月 27日 19時 9分 59秒
|
82
|
+
|
83
|
+
得点(所要時間)は11.0秒
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
2016年 1月 4日 19時 15分 11秒
|
88
|
+
|
89
|
+
得点(所要時間)は8.0秒
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
2016年 1月 4日 19時 16分 8秒
|
94
|
+
|
95
|
+
得点(所要時間)は9.0秒
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
2016年 1月 4日 19時 16分 39秒
|
100
|
+
|
101
|
+
得点(所要時間)は10.0秒
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
2016年 1月 4日 19時 19分 7秒
|
106
|
+
|
107
|
+
得点(所要時間)は10.0秒
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
2016年 1月 4日 19時 21分 11秒
|
112
|
+
|
113
|
+
得点(所要時間)は10.0秒
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
2016年 1月 4日 19時 21分 44秒
|
118
|
+
|
119
|
+
得点(所要時間)は8.0秒
|
120
|
+
|
121
|
+
|
22
122
|
|
23
123
|
...@naka ~/besten
|
24
124
|
|
25
|
-
|
26
|
-
|
27
|
-
...@naka~/besten
|
28
|
-
|
29
|
-
$ bcopy1 dtfile dtfile3
|
30
|
-
|
31
|
-
ファイルdtfileがオープンできません。
|
32
|
-
|
33
|
-
...@naka ~/besten
|
34
|
-
|
35
125
|
$
|
36
126
|
|
37
127
|
|
38
128
|
|
129
|
+
|
130
|
+
|
131
|
+
//並べ替えはquicksortを使う
|
132
|
+
|
133
|
+
//並べ替え後の"LACKNUM.DAT"を表示する。
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
*/
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
39
143
|
###ソースコード
|
40
144
|
|
41
145
|
```
|
42
146
|
|
147
|
+
//ラックナンバーサーチ・トレーニングでベストテンを選び出すフローチャート
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
// 1, ラックナンバーサーチ・トレーニングで実行した日付と実行時間が
|
152
|
+
|
153
|
+
// char dtfile[] = "LACKNUM.DAT" (44バイト)に入っている
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
// 2, 並べ替え前の"LACKNUM.DAT"を表示する。
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
// 3, truct tm localとdouble bestの要素を持つ構造体を定義する。
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
// 4, LACKNUM.DATに保存されているデータを並べ替えて表示する
|
166
|
+
|
167
|
+
// を確保して下さい。
|
168
|
+
|
169
|
+
|
170
|
+
|
43
|
-
/
|
171
|
+
// 5, ソートはその次の段階となります。
|
172
|
+
|
173
|
+
// "LACKNUM.DAT"を"best"の小さい順に並べ替える(そのまま表示する。)
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
// 6, "LACKNUM.DAT"を表示する。
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
|
44
182
|
|
45
183
|
// ラックナンバーサーチ・トレーニング(1部です。必要ないところもあります)
|
46
184
|
|
@@ -68,116 +206,140 @@
|
|
68
206
|
|
69
207
|
#define MAX_NUM 10
|
70
208
|
|
71
|
-
#define BSIZE 44 // この大きさ(44byte)に分割してコピー
|
72
|
-
|
73
209
|
|
74
210
|
|
75
211
|
char dtfile[] = "LACKNUM.DAT"; // ファイル名
|
76
212
|
|
77
|
-
|
213
|
+
|
78
|
-
|
79
|
-
// 十分な数の配列"LACKNUM3.DAT" を確保して下さい。
|
80
214
|
|
81
215
|
typedef struct {
|
82
216
|
|
83
217
|
struct tm local;
|
84
218
|
|
85
|
-
double best
|
219
|
+
double best;
|
86
220
|
|
87
221
|
}time_besten;
|
88
222
|
|
89
223
|
|
90
224
|
|
91
|
-
//void disp(char* , int );
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
int
|
225
|
+
void printData(time_besten data[], int num, char *title)
|
96
226
|
|
97
227
|
{
|
98
228
|
|
99
|
-
|
229
|
+
int i;
|
100
|
-
|
230
|
+
|
101
|
-
|
231
|
+
FILE *fp;
|
102
|
-
|
232
|
+
|
103
|
-
|
233
|
+
double best;
|
234
|
+
|
235
|
+
puts(title);
|
236
|
+
|
237
|
+
//int puts(char * s);
|
238
|
+
|
239
|
+
//puts 関数は標準出力に s が指す文字列を書き込みます.
|
240
|
+
|
241
|
+
//(出力の最後に自動的に改行文字を追加します.)
|
242
|
+
|
243
|
+
//文字列の終端ナル文字 ('\0') の書き込みは行いません.
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
if ((fp = fopen(dtfile, "rb")) == NULL) {
|
250
|
+
|
251
|
+
printf("ファイルを作成します。\n\n");
|
252
|
+
|
253
|
+
best = DBL_MAX; /* float.hに定義されている。double型で表現できる最大値を表すマクロDBL_MAX */
|
254
|
+
|
255
|
+
} else {
|
256
|
+
|
257
|
+
int i;
|
258
|
+
|
259
|
+
struct tm local;
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
while((i = fread(&local, sizeof(struct tm), 1, fp)) > 0 ){
|
264
|
+
|
265
|
+
printf("%d年 %d月 %d日 %d時 %d分 %d秒\n",
|
266
|
+
|
267
|
+
local.tm_year + 1900, local.tm_mon + 1,
|
268
|
+
|
269
|
+
local.tm_mday, local.tm_hour, local.tm_min, local.tm_sec);
|
270
|
+
|
271
|
+
fread(&best, sizeof(double), 1, fp);
|
272
|
+
|
273
|
+
printf("得点(所要時間)は%.1f秒\n\n", best);
|
274
|
+
|
275
|
+
}
|
276
|
+
|
277
|
+
fclose(fp);
|
278
|
+
|
279
|
+
}
|
280
|
+
|
281
|
+
printf("\n");
|
282
|
+
|
283
|
+
}
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
int compfuncBest(const void *a, const void *b)
|
288
|
+
|
289
|
+
{
|
290
|
+
|
291
|
+
double comp;
|
292
|
+
|
293
|
+
comp = ((time_besten*)a)->best - ((time_besten*)b)->best;
|
294
|
+
|
295
|
+
// time_besten型のポインタにキャストしてからメンバbestで比較
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
if (comp<0.) return -1;
|
300
|
+
|
301
|
+
else if (0.<comp) return 1;
|
302
|
+
|
303
|
+
else return 0;
|
304
|
+
|
305
|
+
}
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
int main(void)
|
310
|
+
|
311
|
+
{
|
312
|
+
|
313
|
+
int i,num;
|
314
|
+
|
315
|
+
FILE *fp; // *fpと *fp3はファイルポインタ
|
316
|
+
|
317
|
+
double best;
|
104
318
|
|
105
319
|
time_besten besten;
|
106
320
|
|
321
|
+
|
322
|
+
|
107
|
-
|
323
|
+
int DataSize=sizeof(time_besten);
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
324
|
+
|
112
|
-
|
325
|
+
|
326
|
+
|
113
|
-
|
327
|
+
int NumberOfDatas=sizeof(besten)/DataSize;
|
114
|
-
|
328
|
+
|
329
|
+
|
330
|
+
|
115
|
-
|
331
|
+
printData(&besten , NumberOfDatas, "初期状態");
|
116
|
-
|
117
|
-
|
332
|
+
|
118
|
-
|
119
|
-
|
333
|
+
|
120
|
-
|
121
|
-
|
334
|
+
|
122
|
-
|
335
|
+
|
336
|
+
|
123
|
-
|
337
|
+
qsort(&besten, NumberOfDatas, DataSize, compfuncBest);
|
124
|
-
|
125
|
-
|
338
|
+
|
126
|
-
|
127
|
-
} else if ((fp3 =fopen( *++argv, "wb")) == NULL) {
|
128
|
-
|
129
|
-
fprintf(stderr, "ファイル%sがオープンできません。\n", *argv);
|
130
|
-
|
131
|
-
fclose(fp);
|
132
|
-
|
133
|
-
return (1);
|
134
|
-
|
135
|
-
} else {
|
136
|
-
|
137
|
-
while ( (n = fread(buf, BSIZE, 1, fp)) > 0){
|
138
|
-
|
139
|
-
/* ファイルポインタfpからsizeof(struct tm) バイトのデータを
|
140
|
-
|
141
|
-
1 個読み込み、読み込みデータ格納先のポインタbufに格納する */
|
142
|
-
|
143
|
-
fwrite(buf,n, 1, fp3);
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
339
|
+
printData(&besten, NumberOfDatas, "ベストテン");
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
340
|
+
|
152
|
-
|
153
|
-
|
341
|
+
|
154
|
-
|
155
|
-
|
342
|
+
|
156
|
-
|
157
|
-
fread(&best3,sizeof(double),1, fp3);
|
158
|
-
|
159
|
-
printf("得点(所要時間)は%.1f秒\n\n",besten.best3);
|
160
|
-
|
161
|
-
}
|
162
|
-
|
163
|
-
fflush(stdin);
|
164
|
-
|
165
|
-
getchar();
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
fclose(fp);
|
170
|
-
|
171
|
-
fclose(fp3);
|
172
|
-
|
173
|
-
}
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
}
|
178
|
-
|
179
|
-
}
|
180
|
-
|
181
|
-
|
343
|
+
return 0;
|
182
344
|
|
183
345
|
}
|
1
エラー内容の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -21,12 +21,6 @@
|
|
21
21
|
$ gcc -o bcopy1 bcopy1.c -lpdcursesw
|
22
22
|
|
23
23
|
...@naka ~/besten
|
24
|
-
|
25
|
-
$ bcopy1
|
26
|
-
|
27
|
-
パラメータが不正です。
|
28
|
-
|
29
|
-
bcopy コピー元ファイル名 コピー先ファイル名
|
30
24
|
|
31
25
|
|
32
26
|
|