-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrary.c
More file actions
878 lines (748 loc) · 24.9 KB
/
library.c
File metadata and controls
878 lines (748 loc) · 24.9 KB
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
// Library Management System: Create a program
// that allows users to manage a small library
// by adding, updating, or deleting books,
// authors, and borrowers. Use structures to
// store library data and a file to save and
// load the data.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//////////////////////
// Global variables //
//////////////////////
char data[100]="";
/////////////////////
// books structure //
/////////////////////
struct Book
{
char title[100];
char author[100];
int quantity;
};
/////////////////////////
// borrowers structure //
/////////////////////////
struct Borrower
{
char name[100];
char borrowedBookName[200];
int borrowedBookCount;
};
struct Author
{
char name[100];
int bookCount;
};
// Function to clear console using ncurses library
void clearConsole() {
if(system("cls")==0) system("cls");
else system("clear");
}
/////////////////////////
// functions prototype //
/////////////////////////
int checkFileExists(char *filename);
void MainMenuOptions();
void BookMenuOptions();
void BorrowerMenuOptions();
void AuthorMenuOptions();
///////////////////////////////
// Books functions prototype //
///////////////////////////////
void showBooks();
void addBook();
void updateBook();
void deleteBook();
//////////////////////////////////
// Borrower functions prototype //
//////////////////////////////////
void showBorrowers();
void addBorrower();
void updateBorrower();
void deleteBorrower();
////////////////////////////////
// Author functions prototype //
////////////////////////////////
void showAuthors();
void addAuthors();
void updateAuthor();
void deleteAuthor();
///////////////////
// Main Function //
///////////////////
int main()
{
clearConsole();
// loop for make user input to run until user input 0 to exit to main menu
int mainChoice, bookMenuChoice, borrowerMenuChoice, authorMenuChoice;
// int ;
if (checkFileExists("books.txt") == 0 && checkFileExists("borrowers.txt") == 0 && checkFileExists("authors.txt") == 0){
do{
MainMenuOptions();
scanf("%d", &mainChoice);
getchar(); // consume the newline character left in the input buffer
switch (mainChoice){
// Exit
case 0:
printf("Exiting...\n");
clearConsole();
break;
// Book Menu
case 1:
do{
BookMenuOptions();
scanf("%d", &bookMenuChoice);
getchar(); // consume the newline character left in the input buffer
switch (bookMenuChoice){
case 0:
puts("Going Back...");
clearConsole();
break;
case 1:
showBooks();
break;
case 2:
addBook();
break;
case 3:
updateBook();
break;
case 4:
deleteBook();
break;
default:
strcpy(data,"Invalid choice. Please try again.");
break;
}
} while (bookMenuChoice != 0);
break;
case 2:
do{
BorrowerMenuOptions();
scanf("%d", &borrowerMenuChoice);
getchar(); // consume the newline character left in the input buffer
switch (borrowerMenuChoice){
case 0:
printf("Going Back...\n");
clearConsole();
break;
case 1:
showBorrowers();
break;
case 2:
addBorrower();
break;
case 3:
updateBorrower();
break;
case 4:
deleteBorrower();
break;
default:
strcpy(data,"Invalid choice. Please try again.");
break;
}
} while (borrowerMenuChoice != 0);
break;
case 3:
do{
AuthorMenuOptions();
scanf("%d", &authorMenuChoice);
getchar(); // consume the newline character left in the input buffer
switch (authorMenuChoice){
case 0:
printf("Going Back...\n");
clearConsole();
break;
case 1:
showAuthors();
break;
case 2:
addAuthors();
break;
case 3:
updateAuthor();
break;
case 4:
deleteAuthor();
break;
default:
strcpy(data,"Invalid choice. Please try again.");
break;
}
} while (authorMenuChoice != 0);
break;
default:
strcpy(data,"Invalid choice. Please try again.");
break;
}
} while (mainChoice != 0);
}
return 0;
}
//////////////////////////////////////
// checks if file.txt exists or not //
//////////////////////////////////////
int checkFileExists(char *filename)
{
FILE *file;
if ((file = fopen(filename, "r")))
{
fclose(file);
return 0;
}
else
{
file = fopen(filename, "w");
fclose(file);
return 0;
}
}
///////////////////////
// Main Menu Options //
///////////////////////
void MainMenuOptions(){
puts("///////////////////////////////");
puts("// Library Management System //");
puts("///////////////////////////////\n");
puts("1. Books");
puts("2. Borrowers");
puts("3. Authors");
puts("0. Exit");
// check if data not empty
if (strcmp(data,"")!=0){
puts(data);
strcpy(data,"");
}
printf("Enter your choice: ");
}
///////////////////////
// Book Menu Options //
///////////////////////
void BookMenuOptions(){
clearConsole();
puts("///////////////////");
puts("// Books Section //");
puts("///////////////////\n");
puts("1. Show Books");
puts("2. Add Book");
puts("3. Update Book");
puts("4. Delete Book");
puts("0. Back");
// check if data not empty
if (strcmp(data,"")!=0){
puts(data);
strcpy(data,"");
}
printf("Enter your choice: ");
}
///////////////////////////
// Borrower Menu Options //
///////////////////////////
void BorrowerMenuOptions(){
clearConsole();
puts("///////////////");
puts("// Borrowers //");
puts("///////////////\n");
puts("1. Show Borrowers");
puts("2. Add Borrower");
puts("3. Update Borrower");
puts("4. Delete Borrower");
puts("0. Back");
// check if data not empty
if (strcmp(data,"")!=0){
puts(data);
strcpy(data,"");
}
printf("Enter your choice: ");
}
/////////////////////////
// Author Menu Options //
/////////////////////////
void AuthorMenuOptions(){
clearConsole();
puts("/////////////");
puts("// Authors //");
puts("/////////////");
puts("/////////////\n");
puts("1. Show Authors");
puts("2. Add Author");
puts("3. Update Author");
puts("4. Delete Author");
puts("0. Back");
// check if data not empty
if (strcmp(data,"")!=0){
puts(data);
strcpy(data,"");
}
printf("Enter your choice: ");
}
////////////////
// Show Books //
////////////////
void showBooks(){
clearConsole();
// add data from user input to struct of book and save it to books.txt
int run = 1, count = 0;
do{
checkFileExists("books.txt");
FILE *readfile;
readfile = fopen("books.txt", "r");
puts("////////////");
puts("// Books: //");
puts("////////////\n");
// puts("Title\t\tAuthor\t\tQuantity");
char line[100];
while (fgets(line, 100, readfile)){
printf("%d.\n",++count);
// printf("%s",line);
char *info = strtok(line, ",");
printf("\tTitle: %s\n", info);
info = strtok(NULL, ",");
printf("\tAuthor: %s\n", info);
info = strtok(NULL, ",");
printf("\tQuantity: %s\n\n", info);
}
fclose(readfile);
count = 0;
puts("\n\nEnter 0 to go back: ");
scanf("%d", &run);
getchar(); // consume the newline character left in the input buffer
if (run != 0){
clearConsole();
puts("Invalid input. Please try again.\n");
};
} while (run != 0);
}
///////////////
// Add Books //
///////////////
void addBook(){
clearConsole();
puts("////////////////////");
puts("// Add Book Data: //");
puts("////////////////////\n");
checkFileExists("books.txt");
FILE *writefile;
writefile = fopen("books.txt", "a");
struct Book b1;
printf("Title: ");
fgets(b1.title, 100, stdin);
b1.title[strcspn(b1.title, "\n")] = '\0'; // remove newline character from fgets
printf("Author: ");
fgets(b1.author, 100, stdin);
b1.author[strcspn(b1.author, "\n")] = '\0'; // remove newline character from fgets
printf("quantity: ");
scanf("%d", &b1.quantity);
getchar(); // consume the newline character left in the input buffer
fprintf(writefile, "%s, %s, %d\n", b1.title, b1.author, b1.quantity);
strcpy(data,"Book added successfully.");
fclose(writefile);
}
//////////////////
// Update Books //
//////////////////
void updateBook(){
clearConsole();
puts("///////////////////////");
puts("// Update Book Data: //");
puts("///////////////////////\n");
checkFileExists("books.txt");
checkFileExists("temp.txt");
FILE *readfile, *writefile;
readfile = fopen("books.txt", "r");
writefile = fopen("temp.txt", "w");
printf("Enter book name to update: ");
char searchName[100];
fgets(searchName, 100, stdin);
searchName[strcspn(searchName, "\n")] = '\0'; // remove the newline character from the search string
char line[256], temp[256];
char *pos;
// search for the book name in the file
int bookFound = 0;
while(fgets(line, sizeof(line), readfile)){
strcpy(temp, line);
pos = strstr(line, searchName);
if (pos != NULL && strtok(line, ",") != NULL && strcmp(strtok(line, ","), searchName) == 0){
// update the book data
struct Book b1;
printf("Edit Book Title: ");
fgets(b1.title, 100, stdin);
b1.title[strcspn(b1.title, "\n")] = '\0'; // remove newline character from fgets
printf("Edit Book Author: ");
fgets(b1.author, 100, stdin);
b1.author[strcspn(b1.author, "\n")] = '\0'; // remove newline character from fgets
printf("Edit Book quantity: ");
scanf("%d", &b1.quantity);
getchar(); // consume the newline character left in the input buffer
// write the updated book data to the temp file
fprintf(writefile, "%s, %s, %d\n", b1.title, b1.author, b1.quantity);
bookFound = 1;
}
else {
// write the original book data to the temp file
fprintf(writefile, "%s", temp);
}
}
// File Closing
fclose(readfile);
fclose(writefile);
// replace the original file with the temp file
if (bookFound) {
remove("books.txt");
rename("temp.txt", "books.txt");
strcpy(data,"Book updated successfully.");
}
else {
remove("temp.txt");
strcpy(data,"Book not found.");
}
}
/////////////////
// Delete Book //
/////////////////
void deleteBook() {
clearConsole();
puts("///////////////////////");
puts("// Delete Book Data: //");
puts("///////////////////////\n");
checkFileExists("books.txt");
checkFileExists("temp.txt");
FILE *readfile, *tempfile;
readfile = fopen("books.txt", "r");
tempfile = fopen("temp.txt", "w");
printf("Enter book name to delete: ");
char searchName[100];
fgets(searchName, 100, stdin);
searchName[strcspn(searchName, "\n")] = '\0'; // remove the newline character from the search string
char line[256], temp[256];
char *pos;
// copy all the lines except the one to delete to the temporary file
while (fgets(line, sizeof(line), readfile)) {
strcpy(temp, line);
pos = strstr(line, searchName);
if (pos == NULL && strtok(line, ",") != NULL || strcmp(strtok(line, ","), searchName) != 0){
fprintf(tempfile, "%s", temp);
}
}
fclose(readfile);
fclose(tempfile);
// delete the original file and rename the temporary file to the original file's name
remove("books.txt");
rename("temp.txt", "books.txt");
strcpy(data,"Book deleted successfully.");
}
////////////////////
// Show Borrowers //
////////////////////
void showBorrowers(){
clearConsole();
// add data from user input to struct of Borrower and save it to borrowers.txt
int run = 1, serial = 0;
do{
FILE *readfile;
readfile = fopen("borrowers.txt", "r");
if (readfile == NULL) {
printf("Error opening file.\n");
return;
}
puts("////////////////");
puts("// Borrowers: //");
puts("////////////////\n");
// puts("Title\t\tAuthor\t\tQuantity");
char line[100];
while (fgets(line, 100, readfile)){
printf("%d.\n",++serial);
// printf("%s",line);
char *info = strtok(line, ",");
printf("\tName: %s\n", info);
info = strtok(NULL, ",");
printf("\tQuantity: %s\n\n", info);
}
fclose(readfile);
serial = 0;
puts("\n\nEnter 0 to go back: ");
scanf("%d", &run);
getchar(); // consume the newline character left in the input buffer
if (run != 0){
clearConsole();
puts("Invalid input. Please try again.\n");
};
} while (run != 0);
}
///////////////////
// Add Borrowers //
///////////////////
void addBorrower(){
clearConsole();
puts("////////////////////////");
puts("// Add Borrower Data: //");
puts("////////////////////////\n");
FILE *writefile;
writefile = fopen("borrowers.txt", "a");
struct Borrower b1;
printf("Name: ");
fgets(b1.name, 100, stdin);
b1.name[strcspn(b1.name, "\n")] = '\0'; // remove newline character from fgets
// printf("Author: ");
// fgets(b1.author, 100, stdin);
// b1.author[strcspn(b1.author, "\n")] = '\0'; // remove newline character from fgets
printf("Total: ");
scanf("%d", &b1.borrowedBookCount);
getchar(); // consume the newline character left in the input buffer
fprintf(writefile, "%s, %d\n", b1.name, b1.borrowedBookCount);
strcpy(data,"Borrower added successfully.");
fclose(writefile);
}
//////////////////////
// Update Borrowers //
//////////////////////
void updateBorrower(){
clearConsole();
puts("////////////////////////////");
puts("// Update Borrower Data: //");
puts("////////////////////////////\n");
FILE *readfile, *writefile;
readfile = fopen("borrowers.txt", "r");
writefile = fopen("temp.txt", "w");
checkFileExists("borrowers.txt");
checkFileExists("temp.txt");
printf("Enter Borrower name to update: ");
char searchName[100];
fgets(searchName, 100, stdin);
searchName[strcspn(searchName, "\n")] = '\0'; // remove the newline character from the search string
char line[256], temp[256];
char *pos;
// search for the Borrower name in the file
int BorrowerFound = 0;
while(fgets(line, sizeof(line), readfile)){
strcpy(temp, line);
pos = strstr(line, searchName);
if (pos != NULL && strtok(line, ",") != NULL && strcmp(strtok(line, ","), searchName) == 0){
// update the Borrower data
struct Borrower b1;
printf("Edit Borrower Title: ");
fgets(b1.name, 100, stdin);
b1.name[strcspn(b1.name, "\n")] = '\0'; // remove newline character from fgets
// printf("Edit Borrower Author: ");
// fgets(b1.author, 100, stdin);
// b1.author[strcspn(b1.author, "\n")] = '\0'; // remove newline character from fgets
printf("Edit Borrower quantity: ");
scanf("%d", &b1.borrowedBookCount);
getchar(); // consume the newline character left in the input buffer
// write the updated Borrower data to the temp file
fprintf(writefile, "%s, %d\n", b1.name, b1.borrowedBookCount);
BorrowerFound = 1;
}
else {
// write the original Borrower data to the temp file
fprintf(writefile, "%s", temp);
}
}
// File Closing
fclose(readfile);
fclose(writefile);
// replace the original file with the temp file
if (BorrowerFound) {
remove("borrowers.txt");
rename("temp.txt", "borrowers.txt");
strcpy(data,"Borrower updated successfully.");
}
else {
remove("temp.txt");
printf("Borrower not found.\n");
}
}
/////////////////////
// Delete Borrower //
/////////////////////
void deleteBorrower() {
clearConsole();
puts("///////////////////////////");
puts("// Delete Borrower Data: //");
puts("///////////////////////////\n");
FILE *readfile, *tempfile;
readfile = fopen("borrowers.txt", "r");
tempfile = fopen("temp.txt", "w");
if (readfile == NULL || tempfile == NULL) {
printf("Error opening file.\n");
return;
}
printf("Enter Borrower name to delete: ");
char searchName[100];
fgets(searchName, 100, stdin);
searchName[strcspn(searchName, "\n")] = '\0'; // remove the newline character from the search string
char line[256], temp[256];
char *pos;
// copy all the lines except the one to delete to the temporary file
while (fgets(line, sizeof(line), readfile)) {
strcpy(temp, line);
pos = strstr(line, searchName);
if (pos == NULL && strtok(line, ",") != NULL || strcmp(strtok(line, ","), searchName) != 0){
fprintf(tempfile, "%s", temp);
}
}
fclose(readfile);
fclose(tempfile);
// delete the original file and rename the temporary file to the original file's name
remove("borrowers.txt");
rename("temp.txt", "borrowers.txt");
strcpy(data,"Borrower deleted successfully.");
}
//////////////////
// Show Authors //
//////////////////
void showAuthors(){
clearConsole();
// add data from user input to struct of Author and save it to authors.txt
int run = 1, serial = 0;
do{
FILE *readfile;
readfile = fopen("authors.txt", "r");
if (readfile == NULL) {
printf("Error opening file.\n");
return;
}
puts("//////////////");
puts("// Authors: //");
puts("//////////////\n");
char line[100];
while (fgets(line, 100, readfile)){
printf("%d.\n",++serial);
char *info = strtok(line, ",");
printf("\tName: %s\n", info);
info = strtok(NULL, ",");
printf("\tTotal Book/s Available: %s\n\n", info);
}
fclose(readfile);
serial = 0;
puts("\n\nEnter 0 to go back: ");
scanf("%d", &run);
getchar(); // consume the newline character left in the input buffer
if (run != 0){
clearConsole();
puts("Invalid input. Please try again.\n");
};
} while (run != 0);
}
/////////////////
// Add Authors //
/////////////////
void addAuthors(){
clearConsole();
puts("//////////////////////");
puts("// Add Author Data: //");
puts("//////////////////////\n");
FILE *writefile;
writefile = fopen("authors.txt", "a");
struct Author b1;
printf("Name: ");
fgets(b1.name, 100, stdin);
b1.name[strcspn(b1.name, "\n")] = '\0'; // remove newline character from fgets
// printf("Author: ");
// fgets(b1.author, 100, stdin);
// b1.author[strcspn(b1.author, "\n")] = '\0'; // remove newline character from fgets
printf("Total Book/s Found: ");
scanf("%d", &b1.bookCount);
getchar(); // consume the newline character left in the input buffer
fprintf(writefile, "%s, %d\n", b1.name, b1.bookCount);
strcpy(data,"Author added successfully.");
fclose(writefile);
}
////////////////////
// Update Authors //
////////////////////
void updateAuthor(){
clearConsole();
puts("/////////////////////////");
puts("// Update Author Data: //");
puts("/////////////////////////\n");
FILE *readfile, *writefile;
readfile = fopen("authors.txt", "r");
writefile = fopen("temp.txt", "w");
checkFileExists("authors.txt");
checkFileExists("temp.txt");
printf("Enter Author name to update: ");
char searchName[100];
fgets(searchName, 100, stdin);
searchName[strcspn(searchName, "\n")] = '\0'; // remove the newline character from the search string
char line[256], temp[256];
char *pos;
// search for the Author name in the file
int AuthorFound = 0;
while(fgets(line, sizeof(line), readfile)){
strcpy(temp, line);
pos = strstr(line, searchName);
if (pos != NULL && strtok(line, ",") != NULL && strcmp(strtok(line, ","), searchName) == 0){
// update the Author data
struct Author b1;
printf("Edit Author Title: ");
fgets(b1.name, 100, stdin);
b1.name[strcspn(b1.name, "\n")] = '\0'; // remove newline character from fgets
// printf("Edit Author Author: ");
// fgets(b1.author, 100, stdin);
// b1.author[strcspn(b1.author, "\n")] = '\0'; // remove newline character from fgets
printf("Edit Author quantity: ");
scanf("%d", &b1.bookCount);
getchar(); // consume the newline character left in the input buffer
// write the updated Author data to the temp file
fprintf(writefile, "%s, %d\n", b1.name, b1.bookCount);
AuthorFound = 1;
}
else {
// write the original Author data to the temp file
fprintf(writefile, "%s", temp);
}
}
// File Closing
fclose(readfile);
fclose(writefile);
// replace the original file with the temp file
if (AuthorFound) {
remove("authors.txt");
rename("temp.txt", "authors.txt");
strcpy(data,"Author updated successfully.");
}
else {
remove("temp.txt");
printf("Author not found.\n");
}
}
///////////////////
// Delete Author //
///////////////////
void deleteAuthor() {
clearConsole();
puts("/////////////////////////");
puts("// Delete Author Data: //");
puts("/////////////////////////\n");
FILE *readfile, *tempfile;
readfile = fopen("authors.txt", "r");
tempfile = fopen("temp.txt", "w");
if (readfile == NULL || tempfile == NULL) {
printf("Error opening file.\n");
return;
}
printf("Enter Author name to delete: ");
char searchName[100];
fgets(searchName, 100, stdin);
searchName[strcspn(searchName, "\n")] = '\0'; // remove the newline character from the search string
char line[256], temp[256];
char *pos;
// copy all the lines except the one to delete to the temporary file
while (fgets(line, sizeof(line), readfile)) {
strcpy(temp, line);
pos = strstr(line, searchName);
if (pos == NULL && strtok(line, ",") != NULL || strcmp(strtok(line, ","), searchName) != 0){
fprintf(tempfile, "%s", temp);
}
}
// File Closing
fclose(readfile);
fclose(tempfile);
// delete the original file and rename the temporary file to the original file's name
remove("authors.txt");
rename("temp.txt", "authors.txt");
strcpy(data,"Author deleted successfully.");
}