-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTime_table.c
593 lines (530 loc) · 14.6 KB
/
Time_table.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
#define _CRT_SECURE_NO_WARNINGS
#include "Time_table.h"
#define MAX 100
int size = 0;
void interface_word(char arr1[], char arr2[])
{
if (strcmp(arr2, "") == 0)
{
int size = strlen(arr1);
for (int i = 0; i < (size + 2)/2; i++)
{
printf("■");
}
printf("\n");
printf("%s", arr1);
printf("\n");
for (int i = 0; i < (size + 2)/2; i++)
{
printf("■");
}
printf("\n");
}
else
{
int size1 = strlen(arr1);
int size2 = strlen(arr2);
int max = size1;
bool first_bigger = true;
if (size2 > size1)
{
max = size2;
first_bigger = false;
}
for (int i = 0; i < (max + 2)/2; i++)
{
printf("■");
}
if (first_bigger == true)
{
printf("\n");
printf("%s", arr1);
printf("\n");
printf("\n");
printf("%s", arr2);
for (int i = 0; i < (max - size2); i++)
{
printf(" ");
}
printf("\n");
}
else
{
printf("\n");
printf("%s", arr1);
for (int i = 0; i < max - size2; i++)
{
printf(" ");
}
printf("\n");
printf("\n");
printf("%s", arr2);
printf("\n");
}
for (int i = 0; i < (max + 2)/2; i++)
{
printf("■");
}
printf("\n");
}
}
void print_subject(char arr[], int max)
{
int size = strlen(arr);
for (int i = 0; i < max - size; i++)
{
printf(" ");
}
if (strcmp(arr, "____") == 0)printf(" %s|", " ");
else printf(" %s|", arr);
}
void print_table_format(int size)
{
size = (size + 2) * 6 + 10;
for (int i = 0; i < size; i++)
{
printf("─");
}
printf("\n");
}
int get_max(char arr[][6][MAX])
{
int max = 0;
for (int i = 0; i < 13; i++)
{
for (int j = 0; j < 6; j++)
{
if (strlen(arr[i][j]) > max)max = strlen(arr[i][j]);
}
}
return max;
}
void print_date(int i, int iter)
{
iter = iter - 2;
if (i == 0)
{
printf("Mon");
for (int j = 0; j < iter; j++)
{
printf(" ");
}
printf("|");
}
else if (i == 1)
{
printf("Tue");
for (int j = 0; j < iter; j++)
{
printf(" ");
}
printf("|");
}
else if (i == 2)
{
printf("Wed");
for (int j = 0; j < iter; j++)
{
printf(" ");
}
printf("|");
}
else if (i == 3)
{
printf("Thu");
for (int j = 0; j < iter; j++)
{
printf(" ");
}
printf("|");
}
else if (i == 4)
{
printf("Fri");
for (int j = 0; j < iter; j++)
{
printf(" ");
}
printf("|");
}
else if (i == 5)
{
printf("Sat");
for (int j = 0; j < iter; j++)
{
printf(" ");
}
printf("|");
}
}
void interface_choice(int choice_num, int choice_length, char arr[][MAX])
{
for (int i = 0; i < 15; i++)
{
printf("■");
}
printf("\n");
for (int i = 0; i < 6; i++)
{
printf("■");
}
printf("선택창");
for (int i = 0; i < 6; i++)
{
printf("■");
}
printf("\n");
for (int i = 0; i < 15; i++)
{
printf("■");
}
printf("\n");
switch (choice_num-1)
{
case 1:
interface_one(arr[0]);
interface_zero(arr[choice_num-1]);
break;
case 2:
interface_one(arr[0]);
interface_two(arr[1]);
interface_zero(arr[choice_num-1]);
break;
case 3:
interface_one(arr[0]);
interface_two(arr[1]);
interface_three(arr[2]);
interface_zero(arr[choice_num-1]);
break;
}
for (int i = 0; i < 15; i++)
{
printf("■");
}
printf("\n");
}
void interface_one(char arr[])
{
printf("■■■┌──────────────┐■■■■\n");
printf("■■■│ ■ │■■■■\n");
printf("■■■│ ■■ │■■■■\n");
printf("■■■│ ■ ■ │■■■■\n");
printf("■■■│ ■ │■■■■\n");
printf("■■■│ ■ │■■■■\n");
printf("■■■│ ■ │■■■■\n");
printf("■■■│ ■■■■ │■■■■\n");
printf("■■■│ %s │■■■■\n", arr);
printf("■■■│ │■■■■\n");
printf("■■■└──────────────┘■■■■\n");
}
void interface_two(char arr[])
{
printf("■■■┌──────────────┐■■■■\n");
printf("■■■│ ■■■■ │■■■■\n");
printf("■■■│ ■ ■ │■■■■\n");
printf("■■■│ ■ ■ │■■■■\n");
printf("■■■│ ■ │■■■■\n");
printf("■■■│ ■ │■■■■\n");
printf("■■■│ ■ │■■■■\n");
printf("■■■│ ■■■■■ │■■■■\n");
printf("■■■│ %s │■■■■\n", arr);
printf("■■■│ │■■■■\n");
printf("■■■└──────────────┘■■■■\n");
}
void interface_three(char arr[])
{
printf("■■■┌──────────────┐■■■■\n");
printf("■■■│ ■■■■ │■■■■\n");
printf("■■■│ ■ ■ │■■■■\n");
printf("■■■│ ■ │■■■■\n");
printf("■■■│ ■■■ │■■■■\n");
printf("■■■│ ■ │■■■■\n");
printf("■■■│ ■ ■ │■■■■\n");
printf("■■■│ ■■■■ │■■■■\n");
printf("■■■│ %s │■■■■\n", arr);
printf("■■■│ │■■■■\n");
printf("■■■└──────────────┘■■■■\n");
}
void interface_zero(char arr[])
{
printf("■■■┌──────────────┐■■■■\n");
printf("■■■│ ■■ │■■■■\n");
printf("■■■│ ■ ■ │■■■■\n");
printf("■■■│ ■ ■ │■■■■\n");
printf("■■■│ ■ ■ │■■■■\n");
printf("■■■│ ■ ■ │■■■■\n");
printf("■■■│ ■ ■ │■■■■\n");
printf("■■■│ ■■ │■■■■\n");
printf("■■■│ %s │■■■■\n", arr);
printf("■■■│ │■■■■\n");
printf("■■■└──────────────┘■■■■\n");
}
int find_subject()
{
FILE* fp;
char arr[13][6][MAX] = { 0, };
int idx = 0;
fp = fopen("Time_table_.txt", "rb");
if (fp == NULL)
{
interface_word("Wrong", "");
// printf("Wrong");
return 0;
}
else
{
for (int i = 0; i < 13; i++)
{
for (int j = 0; j < 6; j++)
{
fscanf(fp, "%s", arr[i][j]);
}
}
for (int i = 0; i < 13; i++)
{
for (int j = 0; j < 6; j++)
{
bool arg_not_in = true;
for (int k = 0; k < 10; k++)//check if the subject is in the structure
{
if (strcmp(arr[i][j], "____") == 0)//if no subject, don't print it as a subject
{
arg_not_in = false;
break;
}
else if (strcmp(index[k].subject, arr[i][j]) != 0)//not in specific array
{
continue;
}
else//in specific array
{
arg_not_in = false;//check that the argument is in a specific array
break;
}
}
if (arg_not_in == true)//if the argument is not in a specific array
{
strcpy(index[idx].subject, arr[i][j]);
idx++;
}
}
}
fclose(fp);
size = idx;
}
return size;
}
void show_time_table(char arr[][6][MAX], int size)
{
size = (size + 2) * 3 + 5;
for (int i = 0; i < size / 2 ; i++)
{
printf("■");
}
printf("시간표");
for (int i = 0; i < size / 2; i++)
{
printf("■");
}
printf("\n");
print_table_format(get_max(arr));
printf("|time/day |");
for (int i = 0; i < 6; i++)
{
print_date(i, get_max(arr));//print weekday and weekend
}
printf("\n");
print_table_format(get_max(arr));
for (int i = 0; i < 13; i++)
{
printf("| %02d~%02d |", i + 9, i + 10);//print time
for (int j = 0; j < 6; j++)
{
print_subject(arr[i][j], get_max(arr));//print text read from time_table.txt(class name)
}
printf("\n");
print_table_format(get_max(arr));
}
}
int get_date(char ch[])
{
if (strcmp(ch, "Mon")==0)return 0;
else if (strcmp(ch, "Tue") == 0)return 1;
else if (strcmp(ch, "Wed") == 0)return 2;
else if (strcmp(ch, "Thu") == 0)return 3;
else if (strcmp(ch, "Fri") == 0)return 4;
else if (strcmp(ch, "Sat") == 0)return 5;
else
{
get_date(ch);
}
}
void edit_time_table(FILE* fp, char arr[][6][MAX])
{
char day[10], class_name[MAX];
int Day, start_time, end_time;
char newarr[13][6][MAX] = { 0, };
for (int i = 0; i < 13; i++)
{
for (int j = 0; j < 6; j++)
{
strcpy(newarr[i][j], arr[i][j]);
}
}
ANOTHER:
interface_word("Type in the day you want to deit(ex. Mon)", "or 'next' for next");
// printf("Type in the day you want to edit(ex. Mon)\n");
// printf("or 'next' for next>>");
printf(">>");
scanf("%s", &day);
while (strcmp(day, "next") != 0)
{
printf("\n");
interface_word("Starting time", "");
// printf("Starting time>>");
printf(">>");
scanf("%d", &start_time);
printf("\n");
interface_word("Ending time", "");
// printf("Ending time>>");
printf(">>");
scanf("%d", &end_time);
printf("\n");
interface_word("Class name", "");
// printf("Class name>>");
printf(">>");
scanf("%s", &class_name);
system("cls");
start_time -= 9;
end_time -= 9;
Day = get_date(day);
for (int i = start_time; i < end_time; i++)
{
strcpy(newarr[i][Day], class_name);
}
interface_word("Type in the day you want to edit(ex. Mon)", "or 'next' for next");
// printf("Type in the day you want to edit(ex. Mon)\n");
// printf("or 'next' for next>>");
printf(">>");
scanf("%s", &day);
}
system("cls");
interface_word("[Original version]", "");
// printf("[Original version]\n");
show_time_table(arr, get_max(arr));
interface_word("[Edited version]", "");
// printf("\n[Edited version]\n");
show_time_table(newarr, get_max(newarr));
printf("\n\n");
interface_word("넘어가려면 엔터. . .", "");
// printf("넘어가려면 엔터. . .");
char enter;
scanf("%c%c", &enter);
system("cls");
char interfaces[4][MAX];
strcpy(interfaces[0], "Save the new one");
strcpy(interfaces[1], "Use the original one");
strcpy(interfaces[2], "Additional edit");
interface_choice(3, 100, interfaces);
printf("[선택창]>> ");
int rst = 0;
scanf("%d", &rst);
if (rst == 1)
{
for (int i = 0; i < 13; i++)
{
for (int j = 0; j < 6; j++)
{
fprintf(fp, "%s\n", newarr[i][j]);
}
}
interface_word("edited one saved. . .", "");
// printf("edited one saved. . .");
}
else if (rst == 2)
{
for (int i = 0; i < 13; i++)
{
for (int j = 0; j < 6; j++)
{
fprintf(fp, "%s\n", arr[i][j]);
}
}
interface_word("original one saved. . .", "");
// printf("original one saved. . .");
}
else if (rst == 3)
{
system("cls");
goto ANOTHER;
}
}
void time_table()
{
FILE* in;
char arr[13][6][MAX] = { 0, };
AGAIN:
if ((in = fopen("Time_table_.txt", "rb")) == NULL)//When the file doesn't exists: make new file
{
FILE* make;
make = fopen("Time_table_.txt", "w");
char *str = "____";
for (int i = 0; i < 13; i++)
{
for (int j = 0; j < 6; j++)
{
fprintf(make, "%s\n", str);
}
}
fclose(make);
FILE* in;
goto AGAIN;
}
else
{
for (int i = 0; i < 13; i++)
{
for (int j = 0; j < 6; j++)
{
fscanf(in, "%s", arr[i][j]);//read from the Time_table_.txt
}
}
show_time_table(arr, get_max(arr));
interface_word("넘어가려면 엔터. . .", "");
// printf("넘어가려면 엔터. . .");
char enter;
scanf("%c", &enter);
system("cls");
char interfaces[4][MAX];
strcpy(interfaces[0], "Edit the original one or make a new one");
strcpy(interfaces[1], "Use the original one");
strcpy(interfaces[2], "End the program");
interface_choice(3, 100, interfaces);
fclose(in);
}
FILE* out;
printf("[선택창]>> ");
int rst = 0;
scanf("%d", &rst);
system("cls");
if (rst == 1)//edit. get arguments. Make time table out of these arguments, and save then in Time_table_.txt
{
out = fopen("Time_table_.txt", "w");
ftell(out);
edit_time_table(out, arr);
fclose(out);
}
else if (rst == 2)//use the original
{
interface_word("time table saved. . .", "");
printf("\n\n");
interface_word("See you later. . .", "");
//printf("time table saved. . .\n\n");
//printf("See you later. . .");
}
else if (rst == 0)//end the program
{
interface_word("See you later. . .", "");
// printf("See you later. . .");
}
}