-
Notifications
You must be signed in to change notification settings - Fork 5
/
MoudleAndControl(1.02).h
819 lines (816 loc) · 20.4 KB
/
MoudleAndControl(1.02).h
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
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
#define _CRT_SECURE_NO_WARNINGS
#define MAX_SIZE 1000
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
#include<string.h>
#include<Windows.h>
/*MOUDLE*/
//-----------------------------图书馆-------------------------
typedef struct PriBookClass
{
int id; //书号
char name[20];//书名
char author[20];//作者
char publisher[20];//出版社
int totalMemory;//总内存
int currentMemory;//当前内存
struct PriBookClass *next;
}BookClass;
typedef struct PriLibrary
{//书库整体信息
int totalMemory;//总书数目
int currentMemory;//当前书籍数目
int numOfBookClass;//书籍类别
BookClass *headBookClass;//书籍头指针
}Library;
//-----------------------------个人书库-----------------------
typedef struct PriBorBook
{ //用于保存读者借出的书籍
int id;//所借书籍编号
int amount;//所借书籍数量
}BorBook;
typedef struct PriBorBookSet
{
BorBook *borBooks[MAX_SIZE];
int amount;//总书籍类别
}BorBookSet;
//-----------------------------读者信息-----------------------
typedef struct PriReader
{
int id;
char name[20];
BorBookSet borBookSet;
struct PriReader *next;
}Reader;
typedef struct PriReaderSet
{
int amount;
Reader *headReader;
}ReaderSet;
//-----------------------------借还记录-----------------------
typedef struct PriRecord
{
int readerId;//借书号
int bookId;//书籍号
int amount; //图书数量
char time[30]; //借书时间
char limitedTime[30]; //归还期限
int action;//当前行为
struct PriRecord *next;
}Record;
typedef struct PriRecordSet
{
int amount; //记录数量
Record *headRecord; //头节点
}RecordSet;
//-----------------------------Id检索表-----------------------
typedef struct PriSearchListById
{
int id;
BookClass *bookClass;
}SearchIdNode;
typedef struct PriSearchListByIdSet
{
SearchIdNode searchId[MAX_SIZE];
int amount;
}SearchIdList;
//-----------------------------综合检索表-------------------
typedef struct PriSearchNode
{
char name[20];
char author[20];
char publisher[20];
BookClass *bookClass;
}SearchNode;
typedef struct PriSearchList
{
SearchNode searchNode[MAX_SIZE];
int amount;
}SearchList;
/*Control*/
//-----------------------------个人书库-----------------------
/*查找个人书库的书籍*/
BorBook *searchBorBook(BorBookSet borBookSet, int id)
{
BorBook *borBook = NULL;
for (int i = 0; i < borBookSet.amount; i++)
{
if (id == borBookSet.borBooks[i]->id)
{
borBook = borBookSet.borBooks[i];
}
}
return borBook;
}
/*新增个人书库的书籍*/
int addNewBorBook(BorBookSet *borBookSet, int id, int amount)
{
if (borBookSet->amount + 1 == MAX_SIZE)
{
return 0;
}
else
{
BorBook *borBook = (BorBook *)malloc(sizeof(BorBook));
borBook->amount = amount;
borBook->id = id;
borBookSet->borBooks[borBookSet->amount] = borBook; //ERROR
borBookSet->amount++;
return 1;
}
}
//-----------------------------读者信息-----------------------
/*获取读者最大ID*/
int getReaderMaxId(ReaderSet readerSet)
{
int maxId;
if (readerSet.headReader)
{
maxId = readerSet.headReader->id;
while (readerSet.headReader)
{
maxId = maxId > readerSet.headReader->id ? maxId : readerSet.headReader->id;
readerSet.headReader = readerSet.headReader->next;
}
}
else
{
maxId = 0;
}
return maxId;
}
/*创建读者列表*/
ReaderSet createReaderSet()
{
ReaderSet readerSet;
readerSet.amount = 0;
readerSet.headReader = NULL;
return readerSet;
}
/*
功能:增加读者信息
返回值:读者id
*/
int addReader(ReaderSet *readerSet,char *name)
{
Reader *reader;
reader = (Reader *)malloc(sizeof(Reader));//创建一个读者信息内存块
reader->id = getReaderMaxId(*readerSet) + 1; //使其id成为最大的一个
strcpy(reader->name,name);//存储读者名字
reader->borBookSet.amount = 0;//初始化个人书库数量
reader->next = readerSet->headReader;//读者指针指向下一位读者
readerSet->headReader = reader;
readerSet->amount++;
return reader->id;
}
/*显示读者列表*/
void showReaders(ReaderSet readerSet)
{
void showReaderDetail(ReaderSet readerSet, int id);
printf("->借书号\t姓名\t已借数量\t");
printf("书籍编号\t书籍数目\t\n");
while (readerSet.headReader)
{
printf("->%d\t\t%s\t%d\t\t",
readerSet.headReader->id,
readerSet.headReader->name,
readerSet.headReader->borBookSet.amount);
for (int i = 0; i < readerSet.headReader->borBookSet.amount; i++)
{
printf("%d\t\t%d\t\t", readerSet.headReader->borBookSet.borBooks[i]->id,
readerSet.headReader->borBookSet.borBooks[i]->amount);
}
printf("\n");
readerSet.headReader = readerSet.headReader->next;
}
}
/*显示读者借书详情*/
void showReaderDetail(ReaderSet readerSet,int id)
{
Reader *searchReader(ReaderSet readerSet, int id);
int i;
Reader *reader = NULL;
reader = searchReader(readerSet,id);
printf("->书籍编号|书籍数目\n");
for (i = 0; i < reader->borBookSet.amount;i++)
printf("%d\t|%d\n", reader->borBookSet.borBooks[i]->id, reader->borBookSet.borBooks[i]->amount);
}
/*
功能:根据id查找读者
返回值:读者指针
*/
Reader *searchReader(ReaderSet readerSet, int id)
{
Reader *reader = NULL;
while (readerSet.headReader)
{
if (readerSet.headReader->id == id)
{
reader = readerSet.headReader;
}
readerSet.headReader = readerSet.headReader->next;
}
return reader;
}
/*修改读者名字*/
void alterReader(ReaderSet *readerSet, int id, char *name)
{
Reader *reader;
reader = searchReader(*readerSet,id);
printf("%d..woqu\n",readerSet->headReader->id);
Sleep(5000);
if (reader)
{
strcpy(reader->name,name);
}
else
{
printf("未找到该读者\n");
}
}
/*
功能:删除读者
返回值:0:程序运行正常
*/
int removeReader(ReaderSet *readerSet, int id)
{
Reader *reader=readerSet->headReader;
Reader *temp=readerSet->headReader;
if (reader)
{
if(readerSet->headReader->id == id)//对头结点进行处理
{
if(readerSet->headReader->borBookSet.amount > 0)
{
printf("该读者尚有未归还书籍,无法删除!\n");
return 0;
}
readerSet->headReader = readerSet->headReader->next;
free(temp);
readerSet->amount -= 1;
printf("删除成功\n");
return 0;
}
while(temp)
{
if(temp->id == id)
{
if(temp->borBookSet.amount > 0)
{
printf("该读者尚有未归还书籍,无法删除!\n");
return 0;
}
reader->next = temp->next;
free(temp);
readerSet->amount -= 1;
printf("删除成功\n");
break;
}
else
{
reader = temp;
temp = temp->next;
}
}
}
else
{
printf("当前已申请读者数为0.\n");
Sleep(1000);
}
return 0;
}
/*
功能:为个人书库增加书籍,即借书
返回值:借书书籍数目
*/
int addBorBooks(ReaderSet *readerSet,int readerId,int bookId,int amount)
{
Reader *reader;
BorBook *borBook;
reader = searchReader(*readerSet,readerId);
if (reader)
{
borBook = searchBorBook(reader->borBookSet,bookId);
if (borBook)
{ //已经有这本书
borBook->amount += amount;
}
else
{ //没有这本书
if (!addNewBorBook(&(reader->borBookSet),bookId,amount))
{
amount = 0;
}
}
}
return amount;
}
/*从个人书库取书,即还书*/
int deteleBorBook(ReaderSet *readerSet, int readerId, int bookId, int amount)
{
Reader *reader;
BorBook *borBook;
reader = searchReader(*readerSet, readerId);
if (reader)
{
borBook = searchBorBook(reader->borBookSet, bookId);
if (borBook)
{
amount = amount > borBook->amount ? borBook->amount : amount; //所还的书超出容量
borBook->amount -= amount;
reader->borBookSet.amount -= 1;
}
}
return amount;
}
//-----------------------------借还记录-----------------------
/*创建记录表*/
RecordSet createRecordSet()
{
RecordSet recordSet;
recordSet.amount = 0;
recordSet.headRecord = NULL;
return recordSet;
}
/*添加纪录*/
void addRecord(RecordSet *recordSet,int readerId,int bookId,int amount,int action)
{
Record *record = (Record *)malloc(sizeof(Record));
record->readerId = readerId;
record->bookId = bookId;
record->amount = amount;
record->action = action;
time_t t;
struct tm *timeinfo;
t = time(NULL);
char *time;
time = ctime(&t);
printf("%s\n",time);
t += 2592000;
timeinfo = localtime(&t);
strcpy(record->time,time);
if (action)
{ //借书
strcpy(record->limitedTime, asctime(timeinfo));
}
else
{ //还书
strcpy(record->limitedTime, time);
}
record->next = recordSet->headRecord;
recordSet->headRecord = record;
recordSet->amount++;
}
/*显示记录*/
void showRecord(RecordSet recordSet)
{
while (recordSet.headRecord)
{
printf("->借书证号:%d\t书号:%d\t数量:%d\n日期:%s",
recordSet.headRecord->readerId,
recordSet.headRecord->bookId,
recordSet.headRecord->amount,
recordSet.headRecord->time);
if (recordSet.headRecord->action == 1)
{
printf("截至日期:%s", recordSet.headRecord->limitedTime);
printf("借书\n");
}
else
{
printf("还书\n");
}
recordSet.headRecord = recordSet.headRecord->next;
}
}
//-----------------------------ID索引表-----------------------
/*创建Id索引表
返回值:ID索引表指针
*/
SearchIdList CreateSearchIdList(Library library)
{
SearchIdList searchIdList;
int i = 0;
searchIdList.amount = library.numOfBookClass;//ID检索表的数目等于书籍类别数目
while (library.headBookClass)
{
searchIdList.searchId[i].id = library.headBookClass->id;
searchIdList.searchId[i].bookClass = library.headBookClass;
i++;
library.headBookClass = library.headBookClass->next;//将所有数目类别进行ID索引表建表
}
return searchIdList;
}
/*
功能:通过Id查询
返回值:书籍指针
*/
BookClass *searchById(SearchIdList searchIdList, int id)
{
BookClass *bookClass = NULL;
for (int i = 0; i < searchIdList.amount; i++)
{
if (id == searchIdList.searchId[i].id)
{
bookClass = searchIdList.searchId[i].bookClass;
break;
}
}
return bookClass;
}
//-----------------------------综合检索表-------------------
/*创建综合索引表*/
SearchList createSearchList(Library library)
{
SearchList searchList;
searchList.amount = library.numOfBookClass; //获取书的总类数
int i = 0;
while (library.headBookClass)
{
strcpy(searchList.searchNode[i].name, library.headBookClass->name);
strcpy(searchList.searchNode[i].author, library.headBookClass->author);
strcpy(searchList.searchNode[i].publisher, library.headBookClass->publisher);
searchList.searchNode[i].bookClass = library.headBookClass;
i++;
library.headBookClass = library.headBookClass->next; //指向下一个节点
}
return searchList;
}
/*综合查找*/
int search(SearchList searchList, int index[1000], char *key)
{
//char id[10];
int sign = 0;
for (int i = 0; i < searchList.amount; i++)
{
if (strcmp(searchList.searchNode[i].name, key) == 0||
strcmp(searchList.searchNode[i].author, key) == 0 ||
strcmp(searchList.searchNode[i].publisher,key) == 0)
{ //匹配
index[sign] = i;
sign++;
}
}
return sign;
}
//-----------------------------图书馆-------------------------
/*创建*/
Library createLibrary()
{
Library library;
library.currentMemory = 0;
library.totalMemory = 0;
library.numOfBookClass = 0;
library.headBookClass = NULL;
return library;
}
/*
功能:获取图书馆内书籍最大ID
返回值:最大ID值
*/
int getBookClassMaxId(Library library)
{
int maxId = 0;
while (library.headBookClass)
{
maxId = maxId > library.headBookClass->id ? maxId : library.headBookClass->id;
library.headBookClass = library.headBookClass->next;
}
return maxId;
}
/*综合查询*/
int queryLibrary(Library library, BookClass *bookClasses[MAX_SIZE], char* key)
{
SearchList searchList;
searchList = createSearchList(library); //获得检索线性表
int index[1000];
int length = search(searchList, index, key);
for (int i = 0; i < length; i++)
{
bookClasses[i] = searchList.searchNode[index[i]].bookClass;
}
return length;
}
/*
功能:查询前驱节点
返回值:前驱节点值
*/
BookClass *findPreBookClass(Library library,int id)
{
BookClass *preBookClass = NULL,*bookClass;
if (library.headBookClass)
{
bookClass = library.headBookClass;
while (bookClass && bookClass->id != id)
{
preBookClass = bookClass;
bookClass = bookClass->next;
}
}
return preBookClass;
}
/*ID查询*/
BookClass *queryLibraryById(Library library, int id)
{
BookClass *bookClass;
SearchIdList searchIdList = CreateSearchIdList(library);
bookClass = searchById(searchIdList, id);
return bookClass;
}
/*采编入库*/
void addBooks(Library *library, char *name, char *author,char *publisher, int amount)
{
BookClass *bookClass = NULL;
BookClass *temp = library->headBookClass;
while (temp)
{
if (strcmp(name, temp->name) == 0 &&
strcmp(author,temp->author) == 0 &&
strcmp(publisher,temp->publisher) == 0)
{
bookClass = temp;
break;
}
temp = temp->next;
}
if (!bookClass)
{ //此书在图书馆不存在
bookClass = (BookClass*)malloc(sizeof(BookClass));
strcpy(bookClass->name, name);
strcpy(bookClass->author, author);
strcpy(bookClass->publisher,publisher);
bookClass->currentMemory = amount;
bookClass->totalMemory = amount;
bookClass->id = getBookClassMaxId(*library) + 1;//为其分配最大id
bookClass->next = library->headBookClass;
library->headBookClass = bookClass;
library->numOfBookClass++;
}
else
{
bookClass->currentMemory += amount;
bookClass->totalMemory += amount;
}
library->totalMemory += amount;//图书馆总书籍数目增加
library->currentMemory += amount;
}
/*旧书清零*/
void clearBooks(Library *library, int id)
{
BookClass *preBookClass = NULL;
BookClass *temp;
if (library->headBookClass->id == id)
{ //头节点
temp = library->headBookClass;
library->numOfBookClass--;
library->currentMemory -= temp->currentMemory;
library->totalMemory -= temp->totalMemory;
library->headBookClass = library->headBookClass->next;
free(temp);
printf("->清除完毕。\n");
}
else { //可能存在于后续节点
preBookClass = findPreBookClass(*library, id); //获取前驱节点
if (preBookClass)
{ //存在这本书
temp = preBookClass->next;
library->numOfBookClass--;
library->currentMemory -= temp->currentMemory;
library->totalMemory -= temp->totalMemory;
preBookClass->next = temp->next;
free(temp);
printf("->清除完毕。\n");
}
else
{
printf("->不存在此书。\n");
}
}
}
/*
功能:从图书馆借书
返回值:借书数量
*/
int borrowBooks(Library *library, int id, int amount)
{
BookClass *bookClass;
bookClass = queryLibraryById(*library, id);
if (bookClass)
{
amount = amount > bookClass->currentMemory ? bookClass->currentMemory : amount;
bookClass->currentMemory -= amount;
library->currentMemory -= amount;
}
else
{
amount = 0;
}
return amount;
}
/*还书*/
int returnBooks(Library *library, int id, int amount)
{
BookClass *bookClass = queryLibraryById(*library, id);
if (bookClass)
{
bookClass->currentMemory += amount;
library->currentMemory += amount;
}
else
{
amount = 0;
}
return amount;
}
void showAllBooks(Library *library)
{
int num;
BookClass *temp;
temp = library->headBookClass;
printf("->图书馆目前共有 %d 类书,共有 %d 本书,现有 %d 本。\n",library->numOfBookClass,library->totalMemory,library->currentMemory);
printf("书号\t|书名\t\t 书籍总数目\t馆内现存数目\t\t\t\n");
while(temp)
{
num = strlen(temp->name);
if(num >= 14)
printf("%d\t|%s\t%d\t\t%d\t\t\n",temp->id,temp->name,temp->totalMemory,temp->currentMemory);
else if(num>=8)
printf("%d\t|%s\t\t%d\t\t%d\t\t\n",temp->id,temp->name,temp->totalMemory,temp->currentMemory);
else
printf("%d\t|%s\t\t\t%d\t\t%d\t\t\n",temp->id,temp->name,temp->totalMemory,temp->currentMemory);
temp = temp->next;
}
}
//-----------------------------借书--------------------------
/*借书,返回借的数量*/
int Borrow(Library *library, ReaderSet *readerSet, RecordSet *recordSet, int readerId, int bookId, int amount)
{
amount = borrowBooks(library, bookId, amount); //从图书馆借书
if (amount)
{
int temp = amount;
amount = addBorBooks(readerSet, readerId, bookId, amount); //个人仓库增加书籍
if (amount)
{
addRecord(recordSet, readerId, bookId, amount, 1);
}
else
{ //个人仓库无法添加书籍,把书返回仓库
returnBooks(library, bookId, temp);
}
}
printf("%d\n", amount);
return amount;
}
//-----------------------------还书--------------------------
/*还书,返回还回去的数量*/
int Return(Library *library, ReaderSet *readerSet, RecordSet *recordSet, int readerId, int bookId, int amount)
{
amount = deteleBorBook(readerSet, readerId, bookId, amount); //从个人书库里移除书籍
if (amount)
{
int temp = amount;
amount = returnBooks(library, bookId, amount); //把书返还到图书馆
if (amount)
{
addRecord(recordSet,readerId,bookId,amount,0);
}
else
{
amount = addBorBooks(readerSet,readerId,bookId,temp);
}
}
return amount;
}
/*加载文件*/
void load(char *path1, char *path2, char *path3, Library *library, ReaderSet *readerSet, RecordSet *recordSet)
{
BookClass *bookClass;
Record *record;
Reader *reader;
FILE *file;
file = fopen(path1,"r");
if (file)
{
fscanf(file,"%d\t%d\t%d\n",&library->currentMemory
,&library->totalMemory,
&library->numOfBookClass);
for (int i = 0; i < library->numOfBookClass; i++)
{
bookClass = (BookClass *)malloc(sizeof(BookClass));
fscanf(file,"%d\t%s\t%s\t%s\t%d\t%d\n",
&bookClass->id,
bookClass->name,
bookClass->author,
bookClass->publisher,
&bookClass->totalMemory,
&bookClass->currentMemory); //输入书籍信息
bookClass->next = library->headBookClass;
library->headBookClass = bookClass;
}
fclose(file);
}
file = fopen(path2, "r");
if (file)
{
fscanf(file,"%d\n",&recordSet->amount);
for (int i = 0; i < recordSet->amount; i++)
{
record = (Record *)malloc(sizeof(Record));
fscanf(file,"%d%d%d",
&record->readerId,
&record->bookId,
&record->amount);
fgets(record->time,30,file);
fgets(record->limitedTime, 30, file);
fscanf(file,"%d",&record->action);
record->next = recordSet->headRecord;
recordSet->headRecord = record;
}
fclose(file);
}
file = fopen(path3,"r"); //开始输入个人信息
if (file)
{
fscanf(file,"%d\n",&readerSet->amount);
for (int i = 0; i < readerSet->amount; i++)
{
reader = (Reader *)malloc(sizeof(Reader));
fscanf(file,"%d\t%s\t%d\t",&reader->id,reader->name,&reader->borBookSet.amount);
//int a;
for (int j = 0; j < reader->borBookSet.amount; j++)
{
BorBook *borBook = (BorBook *)malloc(sizeof(BorBook));
reader->borBookSet.borBooks[j] = borBook;
fscanf(file, "%d\t%d\t", &borBook->id,
&borBook->amount);
}
reader->next = readerSet->headReader;
readerSet->headReader = reader;
}
fclose(file);
}
}
/*保存*/
void save(char *path1, char *path2, char *path3, Library library, ReaderSet readerSet, RecordSet recordSet)
{
FILE *file;
file = fopen(path1,"w");//图书馆文件保存
if (file)
{
fprintf(file,"%d\t%d\t%d\n",library.currentMemory,
library.totalMemory,library.numOfBookClass);
while (library.headBookClass)
{
fprintf(file,"%d\t%s\t%s\t%s\t%d\t%d\n",
library.headBookClass->id,
library.headBookClass->name,
library.headBookClass->author,
library.headBookClass->publisher,
library.headBookClass->totalMemory,
library.headBookClass->currentMemory);
library.headBookClass = library.headBookClass->next;
}
fclose(file);
}
file = fopen(path2,"w");//记录文件保存
if (file)
{
fprintf(file,"%d\n",recordSet.amount);
while (recordSet.headRecord)
{
fprintf(file,"%d\t%d\t%d%s%s%d\n",
recordSet.headRecord->readerId,
recordSet.headRecord->bookId,
recordSet.headRecord->amount,
recordSet.headRecord->time,
recordSet.headRecord->limitedTime,
recordSet.headRecord->action);
recordSet.headRecord = recordSet.headRecord->next;
}
fclose(file);
}
file = fopen(path3,"w");//读者文件保存
if (file)
{
fprintf(file,"%d\n",readerSet.amount);
while (readerSet.headReader)
{
fprintf(file,"%d\t%s\t%d\t",
readerSet.headReader->id,
readerSet.headReader->name,
readerSet.headReader->borBookSet.amount);
for (int i = 0; i < readerSet.headReader->borBookSet.amount; i++)
{
fprintf(file,"%d\t%d\t", readerSet.headReader->borBookSet.borBooks[i]->id,
readerSet.headReader->borBookSet.borBooks[i]->amount);
}
fprintf(file,"\n");
readerSet.headReader = readerSet.headReader->next;
}
fclose(file);
}
}