-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBook Database.c
97 lines (87 loc) · 2.02 KB
/
Book Database.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
#include <stdio.h>
#include <string.h>
#define MAX_SIZE 100
typedef struct
{
char Title[MAX_SIZE];
char Author[50];
int year;
}BOOK;
void DisplayMenu()
{
Printf("\nWelcome E-library. How can i help you\n");
printf("1. Add books\n");
}
void Addbooks(BOOK book[], int *size)
{
if (MAX_SIZE > *size)
{
printf("Enter title of book.");
scanf("%[^\n]%*c", book[*size]);
printf("Enter Author of book");
scanf("%[^\n]%*c", book[*size]);
printf("Enter year of book");
scanf("%d", book[*size].year);
(*size)++;
}
else
{
printf("Sorry the stroge is full cannot add more!\n");
}
}
void Delete(BOOK Books[], int *size, char Delete)
{
for (int i = 0; i < size; i++)
{
if (strcmp(Books[i].Title, Delete) == 0)
{
Books[i] = Books[i + 1];
printf("Deleted successfull\n");
(*size)--;
break;
}
}
}
int main()
{
BOOK Books[MAX_SIZE];
int size = 0;
int choice;
do
{
DisplayMenu();
printf("Enter your chpice: ");
scanf("%d ", &choice);
switch(choice)
{
case 1:
{
Addbooks(Books, &size);
break;
}
case 2:
{
int Delete[MAX_SIZE];
printf("Enter Book Name to delete: ");
scanf("%{^\n}s", Delete);
DeleteBook(Books, size, Delete);
break;
}
case 3:
{
Display(Books, size);
break;
}
case 4:
{
printf("Exiting From The Book Data Base.\n");
break;
}
default:
{
printf("You choose an wrong number.\n");
}
}
} while (choice != 4);
return 0;
}