-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathQ24.c
More file actions
107 lines (101 loc) · 2.42 KB
/
Q24.c
File metadata and controls
107 lines (101 loc) · 2.42 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
/* Program: 24
Write a menu driven program in 'C' which shows the working of library.
The menu option should be
(i) Add book details.
(ii) Display book details.
(iii) List all books of given author.
(iv) List the count of books in the library.
(v) Exit.
*/
#include <stdio.h>
#include <string.h>
int c = 0, i;
struct book
{
char name[30];
char author[30];
} book[500];
void addBook(char name[], char author[])
{
int count = countBook();
strcpy(book[count].name, name);
strcpy(book[count].author, author);
c++;
}
int countBook()
{
return c;
}
void displayBook()
{
for (i = 0; i < countBook(); i++)
{
printf("\t%d. book details", i + 1);
printf("\nBook name : %s", book[i].name);
printf("\nBook author : %s\n", book[i].author);
}
}
void allBookGivenAuthor()
{
for (i = 0; i < countBook(); i++)
printf("\n%d. Book author : %s\n", i + 1, book[i].author);
}
int main()
{
do
{
int ch;
char name[30], author[30];
printf("\n\t1. Add book details.\n");
printf("\t2. Display book details.\n");
printf("\t3. List all books of given author.\n");
printf("\t4. List the count of books in the library.\n");
printf("\t5. Exit.\n");
printf("\nEnter the choice: ");
scanf("%d", &ch);
fflush(stdin);
switch (ch)
{
case 1:
{
printf("\n\t______Add book details______\n");
printf("Enter a new book name : ");
gets(name);
printf("Enter Book author name : ");
gets(author);
addBook(name, author);
}
break;
case 2:
{
printf("\n\t_______Display book details______\n");
displayBook();
}
break;
case 3:
{
printf("\n\t______List all books of given author______\n");
allBookGivenAuthor();
}
break;
case 4:
{
printf("\n\t______List the count of books in the library______\n");
printf("\n%d Book in the library\n", countBook());
}
break;
case 5:
{
exit(0);
}
break;
default:
{
printf("\n\t......invalid input..........\n");
printf("\tPlease choose the correct option...\n");
}
break;
}
} while (1);
return 0;
}