-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrarymanagment.c
1241 lines (1139 loc) · 34.1 KB
/
librarymanagment.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
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
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<windows.h>
#include<string.h>
#include<time.h>
#include<stdbool.h>
void resetColor(){ /// reset the old color of console
printf("\033[0m");
}
// System Operation Functions
void password(void);
void menu(void);
void user_menu();
void userPanel(void);
void bookPanel(void);
void password_menu();
void Ragister();
void Login();
void forget_password();
// user operation function
void modifyUser();
void listUser();
int searchUser();
void deleteUser();
void list_books();
void searchByName();
void searchByID();
void searchbooks();
void view_issueinfo();
void gotoxy(int , int);
// Staff Operation Function
void addUser();
void bookPanal();
void view_books();
void search_book();
void issue_book();
void return_book();
void remove_book();
void book_menu();
void user_search();
void add_book();
// Supporting Function
void replaceInFile();
void view_list();
void due_date();
bool checkid();
bool checkuser();
void getuserdata();
char uid2[12];
struct library{
char Book_Name[50];
char Author_Name[20];
char Book_Number[10];
char edition[5];
char rack[8];
char price[8];
char category[20];
char year_publication[6];
char issued[3];
char issue_to[20];
char issue_date[20];
char duedate[20];
};
struct library book;
struct user{
char username[20];
char gender[2];
char phone[11];
char userId[11];
char Password[12];
};
struct user user;
int main(){
resetColor();
system("cls");
printf("\n====================================================");
printf("\n >>>>> LIBRARY RECORD MANAGEMENT SYSTEM <<<<<< \n");
printf(" ====================================================\n\n\n");
printf("Press any key to continue ");
getch();
system("cls");
menu();
}
void password(){
char user[8];
char userid[8]={"Admin"};
char pwd[255];
char code[255]={"Admin"};
printf("--------------------\n");
printf(">>> Login First <<<\n");
printf("--------------------\n\n");
printf("Enter your username: ");
scanf("%s", user);
printf("Enter your password: ");
scanf("%s", pwd);
// verifies the password
if(!strcmp(user, userid))
{
if(!strcmp(pwd, code)){
book_menu();
}else{
printf("\nInvaild Password!\n");
password();
}
}
else
{
printf("\nInvaild Username!\n");
password();
}
}
void password_menu(){
int choice;
system("cls");
printf("\n====================================================");
printf("\n >>>>> USER ACCOUNT RAGISTRATION <<<<<< \n");
printf(" ====================================================\n\n");
printf(">> 1. RAGISTER \n");
printf(">> 2. LOGIN \n");
printf(">> 3. FORGATE PASSWORD \n\n");
fflush(stdin);
printf("enter choice : ");
scanf("%d",&choice);
switch(choice){
case 1:
Ragister();
break;
case 2:
Login();
break;
case 3:
forget_password();
break;
default:
printf("Invalid entry ..\n");
}
}
void Ragister(){
struct user user;
printf("--------------------\n");
printf(">>> Ragister Yourself <<<\n");
printf("--------------------\n\n");
FILE *pF = fopen("user_Records.txt", "ab");
if(pF != NULL)
{
fflush(stdin);
printf("Enter the Name: ");
gets(user.username);
printf("Enter Gender [M/F]: ");
gets(user.gender);
printf("Enter Phone Number: ");
gets(user.phone);
printf("Enter User ID: ");
gets(user.userId);
printf("Enter password : ");
gets(user.Password);
fwrite(&user,sizeof(user),1,pF);
printf("\n>>> you Ragister Successfully <<< \n");
}
else{
printf("\n >>>> you have somthing error <<<< \n");
}
fclose(pF);
fflush(stdin);
printf("press any key to continue.... ");
getch();
password_menu();
}
void Login(){
system("cls");
struct user user;
char uid[12];
char pass[12];
int found=0;
printf("--------------------\n");
printf(">>> Login Yourself <<<\n");
printf("--------------------\n\n");
fflush(stdin);
printf("USERNAME : ");
gets(uid);
printf("PASSWORD : ");
gets(pass);
FILE *pF = fopen("user_Records.txt", "rb");
if(pF == NULL){
printf("\n You are enable to login ");
}
while(fread(&user,sizeof(user),1,pF)==1){
if(strcmp(user.userId,uid)==0 && strcmp(user.Password,pass)==0){
printf(" \n\n >> you login succesfully << \n");
found=1;
strcpy(uid2,uid);
}
}
if(found==0){
printf("\n\n >>> You have enterd wrong password or username <<<< \n");
fclose(pF);
password_menu();
}
else{
fclose(pF);
fflush(stdin);
printf("press any key to continue : ");
getch();
user_menu();
}
}
void forget_password(){
printf("--------------------\n");
printf(">>> Forget password <<<\n");
printf("--------------------\n\n");
struct user user;
char pass[12] ,pass1[12];
int flag=0;
char find[9];
srand(time(NULL));
int n = 1000 + rand()%100;
printf("CAPTCHA CODE \n %d \n",n);
int captcha;
printf("Enetr captcha value : ");
scanf("%d",&captcha);
fflush(stdin);
if(captcha == n){
printf("Enter the user ID for forget password : ");
gets(find);
FILE *pF = fopen("user_Records.txt", "rb");
FILE *pT = fopen("temporary.txt", "ab");
while(fread(&user,sizeof(struct user),1,pF)==1){
if(strcmp(find,user.userId)==0){
fflush(stdin);
printf(">> Enetr password : ");
gets(pass);
printf(">> Confirm password : ");
gets(pass1);
if(strcmp(pass , pass1)==0){
strcpy(user.Password,pass);
fwrite(&user,sizeof(user),1,pT);
printf("\n\nProcessing your changes....");
}
else{
printf("\n password not matched \n");
}
flag = 1;
}
else{
fwrite(&user,sizeof(user),1,pT);
}
}
fflush(stdin);
fclose(pF);
fclose(pT);
if(flag == 0){
printf("\n\n-------------------------------\n");
printf(">>> Record Not Found <<<\n");
printf("-------------------------------\n\n");
printf("Redirecting to User Panel...");
pT = fopen("temporary.txt", "wb");
fclose(pT);
printf("\n press key to continue \n");
getch();
password_menu();
}
pF = fopen("user_Records.txt", "wb");
fclose(pF);
pF = fopen("user_Records.txt", "ab");
pT = fopen("temporary.txt", "rb");
while(fread(&user,sizeof(user),1,pT)==1){
fwrite(&user,sizeof(user),1,pF);
}
fclose(pF);
fclose(pT);
pT = fopen("temporary.txt", "wb");
fclose(pT);
}
else{
printf("\n Invalid captcha code \n");
}
printf("\n press any key to continue ");
getch();
password_menu();
}
// Main Selection menu between User & Book Panel
void menu(){
system("cls");
int number;
printf("----------------------------------\n");
printf(">>> Library Management System <<< \n");
printf("----------------------------------\n\n");
printf("> 1. User Management Panel \n");
printf("> 2. Book Management Panel \n");
printf("> 3. Exit programe \n\n");
printf("> Enter the number: ");
scanf("%d",&number);
switch(number)
{
case 1:
userPanel();
break;
case 2:
bookPanel();
break;
case 3:
exit(0);
break;
default:
printf("\n>>> Invaild Input! <<<");
menu();
}
}
void bookPanel(){
printf("-----------------------------------------------\n");
printf(">>> Library Management System - Book Panel <<< \n");
printf("-----------------------------------------------\n\n");
password();
}
void userPanel(){
printf("-----------------------------------------------\n");
printf(">>> Library Management System - Book Panel <<< \n");
printf("-----------------------------------------------\n\n");
password_menu();
}
void user_menu(){
system("cls");
char uid1[12];
strcpy(uid1,uid2);
int number;
printf("-----------------------------------------------\n");
printf(">>> Library Management System - User Menu <<< \n");
printf("-----------------------------------------------\n\n");
printf("> 1. Search book \n");
printf("> 2. List of issued book \n");
printf("> 3. List of Books \n");
printf("> 4. Modify User \n");
printf("> 5. Search User \n");
printf("> 6. Delete User \n");
printf("> 7. Open Main Menu \n");
printf("> 8. Close the Program... \n\n");
printf("> Enter the number & hit ENTER: ");
scanf("%d",&number);
switch(number)
{
case 1:
search_book();
break;
case 4:
modifyUser(uid1);
break;
case 2:
view_issueinfo(uid1);
break;
case 3:
list_books();
break;
case 5:
searchUser();
break;
case 6:
deleteUser(uid1);
break;
case 7:
menu();
break;
case 8:
exit(0);
break;
default:
printf("Invaild Input!");
userPanel();
}
}
void addUser(){
label1:
system("cls");
FILE *pF = fopen("user_Records.txt", "ab");
if(pF != NULL)
{
fflush(stdin);
printf("Enter the First Name: ");
gets(user.username);
printf("Enter Gender [M/F]: ");
gets(user.gender);
printf("Enter Phone Number: ");
gets(user.phone);
printf("Enter User ID: ");
gets(user.userId);
printf("Enter the Last Name: ");
gets(user.Password);
fwrite(&user,sizeof(user),1,pF);
printf("\n>>> User Record Added Successfully <<< \n");
}
else
{
printf("Unable to open/locate the file.");
}
fclose(pF);
char input;
retry:
//retry screen
printf("\nDo you wanna enter more records [Y/N]: ");
scanf(" %c",&input);
if(input == 'y' || input=='Y')
{
goto label1;
}
else if(input=='n' || input=='N')
{
printf("\nRedirecting to User Panel.");
book_menu();
}
else
{
printf("\nInvaild input. Redirecting to User Panel.");
goto retry;
}
}
void modifyUser(char uid[]){
system("cls");
char name1[255], gender1[5];
char uid1[9];
char phone1[11];
int flag=0;
char find[9];
strcpy(uid1,uid);
FILE *pF = fopen("user_Records.txt", "rb");
FILE *pT = fopen("temporary.txt", "ab");
while(fread(&user,sizeof(struct user),1,pF)==1)
{
if(strcmp(find,user.userId)==0)
{
printf("\n---------------------------------------------\n");
printf(">>> Record Found, Allowing Modifications <<<\n");
printf("-----------------------------------------------\n\n");
fflush(stdin);
printf("> Enter First Name: ");
gets(name1);
strcpy(user.username,name1);
printf("> Enter Gender [M/F]: ");
gets(gender1);
strcpy(user.gender,gender1);
fflush(stdin);
printf("> Enter Student ID: ");
gets(uid1);
strcpy(user.userId,uid1);
fflush(stdin);
printf("> Enter Phone Number: ");
gets(phone1);
strcpy(user.phone,phone1);
fwrite(&user,sizeof(user),1,pT);
printf("\n\nProcessing your changes....");
flag = 1;
}
else
{
fwrite(&user,sizeof(user),1,pT);
}
}
fflush(stdin);
fclose(pF);
fclose(pT);
if(flag == 0)
{
printf("\n\n-------------------------------\n");
printf(">>> Record Not Found <<<\n");
printf("-------------------------------\n\n");
printf("Redirecting to User Panel...");
pT = fopen("temporary.txt", "wb");
fclose(pT);
userPanel();
}
pF = fopen("user_Records.txt", "wb");
fclose(pF);
pF = fopen("user_Records.txt", "ab");
pT = fopen("temporary.txt", "rb");
while(fread(&user,sizeof(user),1,pT)==1)
{
fwrite(&user,sizeof(user),1,pF);
}
fclose(pF);
fclose(pT);
pT = fopen("temporary.txt", "wb");
fclose(pT);
userPanel();
}
void listUser(){
system("cls");
FILE *pF = fopen("user_Records.txt", "rb");
int empty=1;
printf("-------------------------------\n");
printf(">>> List of Users Record <<< \n");
printf("-------------------------------\n\n");
while(fread(&user,sizeof(user),1,pF)==1){
printf("-------------------------------\n");
printf("> Full Name: %s \n", user.username);
//printf("> Last Name: %s \n", lname);
printf("> Gender: %s \n", user.gender);
printf("> Student-ID: %s \n", user.userId);
printf("> Phone No.: %s \n", user.phone);
printf("-------------------------------\n\n\n");
empty=0;
}
fclose(pF);
if(empty)
{
printf("-------------------------------------\n");
printf("There is no user records added yet...\n");
printf("--------------------------------------\n\n");
}
printf("Press any key to get back to User Panel.\n");
getch();
book_menu();
}
int searchUser(){
label2:
system("cls");
int flag=0;
//int compare;
char find[9];
printf("Search by User ID of the student: ");
scanf("%s", find);
FILE *pF = fopen("user_Records.txt", "rb");
while(fread(&user,sizeof(user),1,pF)==1)
{
//strcmp(variable, variable1) -- if both the strings are equal then it will return 0 otherwise a random number.
//compare = strcmp(find, uid);
if(!strcmp(find, user.userId))
{
printf("\n---------------------\n");
printf(">>> Record Found <<< \n");
printf("---------------------\n\n");
printf("-------------------------------\n");
printf("> Full Name: %s \n", user.username);
printf("> Gender: %s \n", user.gender);
printf("> Student-ID: %s \n", user.userId);
printf("> Phone Number: %s \n", user.phone);
printf("-------------------------------\n\n");
flag=1;
}
}
fclose(pF);
if(flag == 0)
{
printf("\n>>> Record Not Found <<< \n\n");
}
printf("Press any key to redirect back to Panel.");
getch();
user_menu();
}
void deleteUser(char uid[]){
system("cls");
int flag=0;
fflush(stdin);
char find[9];
strcpy(find,uid);
FILE *pF = fopen("user_Records.txt", "rb");
FILE *pT = fopen("temporary.txt", "ab");
if(pF==NULL && pT ==NULL){
printf("file cant open ");
}
while(fread(&user,sizeof(user),1,pF)==1)
{
if(strcmp(find, user.userId)==0)
{
printf("\n---------------------------------------------\n");
printf(">>> Record Deleted <<<\n");
printf("-----------------------------------------------\n\n");
printf("Redirecting to User Panel...");
flag = 1;
}
else
{
fwrite(&user,sizeof(user),1,pT);
}
}
fclose(pF);
fclose(pT);
pF = fopen("user_Records.txt", "wb");
fclose(pF);
if(flag == 0)
{
printf("\n\n-------------------------------\n");
printf(">>> Record Not Found <<<\n");
printf("-------------------------------\n\n");
printf("Redirecting to User Panel...");
}
pF = fopen("user_Records.txt", "ab");
pT = fopen("temporary.txt", "rb");
while(fread(&user,sizeof(user),1,pT)==1)
{
fwrite(&user,sizeof(user),1,pF);
}
fclose(pF);
fclose(pT);
pT = fopen("temporary.txt", "wb");
fclose(pT);
userPanel();
}
void book_menu(){
int choice;
system("cls");
gotoxy(5,3);
printf("\n---------------------------------------------\n");
printf(">>> BOOK MENU <<<\n");
printf("-----------------------------------------------\n");
printf("\n-----------------------------\n");
printf(" 1 : Add Books \n");
printf(" 2 : View Books \n");
printf(" 3 : List of User \n");
printf(" 4 : Issue Books \n");
printf(" 5 : Return Books \n");
printf(" 6 : Delete Books \n");
printf(" 7 : user information \n");
printf(" 8 : Add User \n");
printf(" 9 : menu \n");
printf("-------------------------------\n");
fflush(stdin);
printf(">>Enter choice : ");
scanf("%d",&choice);
switch(choice){
case 1:
add_book();
break;
case 2:
view_books();
break;
case 3:
listUser();
break;
case 4:
issue_book();
break;
case 5:
return_book();
break;
case 6:
remove_book();
break;
case 7:
user_search();
break;
case 8:
addUser();
break;
case 9:
menu();
default:
gotoxy(15,14);
printf("Invalid Entry... \n");
}
}
void add_book(){
FILE *ptr;
char b[2]={0};
char a ='y';
struct library book;
ptr = fopen("book.txt","ab");
if(ptr == NULL){
printf("Error opening file");
exit(1);
}
fflush(stdin);
while( a == 'y'){
printf("\n---------------------------------------------\n");
printf(">>> ADD BOOK DATA <<<\n");
printf("-----------------------------------------------\n\n");
printf(">>>Book Name ");
gets(book.Book_Name);
printf(">>>Author Name ");
gets(book.Author_Name);
printf(">>>Publication year ");
gets(book.year_publication);
printf(">>>Book Number ");
gets(book.Book_Number);
printf(">>>Edition of Book ");
gets(book.edition);
printf(">>>category of Book ");
gets(book.category);
printf(">>>price of Book ");
gets(book.price);
printf(">>>rack no of Book ");
gets(book.rack);
fwrite(&book,sizeof(struct library),1,ptr);
printf("Enter Y to continue or N to leave..... ");
scanf("%c",&a);
}
fclose(ptr);
printf("Press any key to continue....");
getch();
book_menu();
}
void list_books(){
FILE *fptr;
//struct library lib;
fptr=fopen("book.txt","rb");
printf("\n---------------------------------------------\n");
printf(">>> VIEW BOOK DATA <<<\n");
printf("-----------------------------------------------\n\n");
while(fread(&book,sizeof(struct library),1,fptr)==1){
printf("\n-------------------------------------------\n\n");
printf(">>book name %s \n",book.Book_Name);
printf(">>auther name %s \n",book.Author_Name);
printf(">>book published %s \n",book.year_publication);
printf(">>book number %s \n",book.Book_Number);
printf(">>book edition %s \n",book.edition);
printf(">>book price %s \n",book.price);
printf(">>rack no %s \n",book.rack);
printf("\n-------------------------------------------\n\n");
}
fclose(fptr);
printf("press any key to continue....");
getch();
user_menu();
}
void search_book()
{
system("cls");
printf("\n---------------------------------------------\n");
printf(">>> SEARCH BOOK DATA <<<\n");
printf("-----------------------------------------------\n\n");
printf("\n\n");
printf("1. Search By ID");
printf("\n\n");
printf(" 2. Search By Name");
printf("\n\n");
printf("Enter Your Choice.....");
fflush(stdin);
switch(getch())
{
case '1':
searchByID();
break;
break;
case '2':
searchByName();
break;
default :
getch();
search_book();
}
}
void issue_book(){
printf("\n---------------------------------------------\n");
printf(">>> ISSUE BOOK <<<\n");
printf("-----------------------------------------------\n\n");
char bookid[10];
char id_no[15];
char name[50];
int day=0,month=0,year=0;
char date[6];
struct library book;
printf("Enter book number to be issued : ");
fflush(stdin);
gets(bookid);
time_t current_time = time(NULL);
time_t now;
time(&now);
struct tm *currentDate = localtime(&now);
char date_string[20];
strftime(date_string, 20, "%Y-%m-%d", localtime(¤t_time));
FILE *fptr;
FILE *ptr;
FILE *file;
fptr=fopen("book.txt","rb+");
file =fopen("issue.txt","ab");
if(fptr==NULL && ptr == NULL){
printf("Error in file opening ");
}
due_date(20,currentDate);
day=currentDate->tm_mday;
month=currentDate->tm_mon;
year=currentDate->tm_year + 1900;
strftime(date,20,"%Y-%m-%d",currentDate);
free(currentDate);
if(checkid(bookid)){
printf("Enter user id : ");
gets(id_no);
while(fread(&book,sizeof(book),1,fptr)==1){
if(strcmp(book.Book_Number,bookid)==0){
strcpy(book.issue_to,id_no);
strcpy(book.issue_date,date_string);
strcpy(book.duedate,date);
fwrite(&book,sizeof(struct library),1,file);
printf("\n=============================================\n");
printf(">>>>>>> book issued successfully <<<<<<<<<<\n");
printf("\n=============================================\n");
fclose(file);
}
fflush(stdin);
}
}
else{
printf("book not available in library \n");
}
fclose(fptr);
printf("press any key for continue.....");
getch();
fflush(stdin);
book_menu();
}
void return_book(){
printf("\n---------------------------------------------\n");
printf(">>> RETURN BOOK <<<\n");
printf("-----------------------------------------------\n\n");
int found =0;
char bookid[10];
char uid1[12];
fflush(stdin);
printf("book number to be return : ");
gets(bookid);
printf("user id :");
gets(uid1);
printf("\n");
FILE *fptr;
fptr=fopen("issue.txt","rb");
if(fptr==NULL){
printf("Error in filr opening ");
}
while(fread(&book ,sizeof(book),1,fptr)==1){
found=1;
if(strcmp(book.Book_Number,bookid)==0){
view_list(bookid,uid1);
printf("\n===============================================\n");
printf(">>>>>>>>>> book returned successfully <<<<<<<<<\n");
printf("\n===============================================\n");
}
}
if(found==0){
printf("Somthing went Wrong ...... \n ");
}
fclose(fptr);
printf("Press any key to continue.");
getch();
book_menu();
}
void remove_book(){
printf("\n---------------------------------------------\n");
printf(">>> BOOK Record Delete <<<\n");
printf("-----------------------------------------------\n\n");
char bookid[100];
fflush(stdin);
printf("Enter name of book you want to delete ");
gets(bookid);
FILE *fptr;
FILE *ptr;
int found=0;
struct library book;
fptr=fopen("book.txt","rb");
ptr=fopen("tem.txt","wb");
if(fptr ==NULL && ptr==NULL){
printf("Error in file opening ");
}
while (fread(&book,sizeof(struct library),1,fptr)==1){
if (strcmp(book.Book_Name,bookid)==0){
printf("\n====================================================\n");
printf(" \n A Record with requested Name found and deleted.\n\n");
printf("\n====================================================\n");
found=1;
}
else {
fwrite(&book, sizeof(struct library), 1, ptr);
}
}
if (found==0) {
printf(" \n No record(s) found with the requested name of book : %s\n\n",bookid);
}
fclose(fptr);
fclose(ptr);
fptr = fopen("book.txt", "wb");
fclose(fptr);
fptr = fopen("book.txt", "ab");
ptr = fopen("tem.txt", "rb");
while(fread(&user,sizeof(user),1,ptr)==1){
fwrite(&user,sizeof(user),1,fptr);
}
fclose(fptr);
fclose(ptr);
ptr= fopen("tem.txt", "wb");
fclose(ptr);
fflush(stdin);
printf("press any key to continue.....");
getch();
book_menu();
}
void view_books(){
FILE *fptr;
//struct library lib;
fptr=fopen("book.txt","rb");
printf("\n---------------------------------------------\n");
printf(">>> VIEW BOOK DATA <<<\n");
printf("-----------------------------------------------\n\n");
while(fread(&book,sizeof(struct library),1,fptr)==1){
printf("\n-------------------------------------------\n\n");
printf(">>book name %s \n",book.Book_Name);
printf(">>auther name %s \n",book.Author_Name);
printf(">>book published %s \n",book.year_publication);
printf(">>book number %s \n",book.Book_Number);
printf(">>book edition %s \n",book.edition);
printf(">>book price %s \n",book.price);
printf(">>rack no %s \n",book.rack);
printf("\n-------------------------------------------\n\n");
}
fclose(fptr);
printf("press any key to continue....");
getch();
book_menu();
}
void user_search(){
FILE *fptr;