C Chapters

C program to create menu driven program that depicts the working
of a library. The menu options should be:
Add book information
Display book information
1.List all books of given author
2.List the title of specified book
3.List the count of books in the library
4.List the books in the order of accession number
5.Exit
Create a structure called library to hold accession number,
title of the book, author name, price of the book, and flag
indicating whether book is issued or not.

Structures & Functions - Structures
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>

void add_book();
void disp_book();
void book_auth();
void count_book();

struct lib
{
	int acc_no;
	char book_title[20];
	char author[20];
	int cost;
}b[100];
int count;
int main()
{
	int ch;
	while(1)
	{
		printf("\n 1:Enter the book info\n");
		printf("\n 2:Display book info\n");
		printf("\n 3:Book author\n");
		printf("\n 4:Count book\n");
		printf("\n 5:Exit\n");
		printf("\n Enter the choice \n");
		scanf("%d",&ch);
		switch(ch)
		{
			case 1:
				add_book();
				getch();
				break;
			case 2:
				disp_book();
				getch();
				break;
			case 3:
				book_auth();
				getch();
				break;
			case 4:
				count_book();
				getch();
				break;
			case 5:
				exit(0);
			}
		}
}

void add_book()
{
	if(count==9)
	{
		printf("\n No more space\n");
		return;
	}
	printf("\n Enter the detail of book \n");
	printf("\n Enter accession number of book =");
	scanf("%d",&b[count].acc_no);
	fflush(stdin);
	printf("\n Enter the book title=");
	gets(b[count].book_title);
	fflush(stdin);
	printf("\n Enter the name of author=");
	gets(b[count].author);
	fflush(stdin);
	printf("\n Enter the cost of book=");
	scanf("%d",&b[count].cost);
	count++;
}
void disp_book()
{
	int i;
	printf("\n Detail of %d booksin library",count);
	for(i=0;i<count;i++)
	{
		printf("\n %d\n%s\n%s\n%d",b[i].acc_no,b[i].book_title,b[i].author,b[i].cost);
	}
}

void book_auth()
{
	int i,cnt=0;
	char name[20];
	printf("\n Enter the name of author= ");
	fflush(stdin);
	gets(name);
	for(i=0;i<count;i++)
	{
		if(strcmp(name,b[i].author)==0)
		{
			cnt++;
			printf("\n %d\n%s\n%s\n%d",b[i].acc_no,b[i].book_title,b[i].author,b[i].cost);
		}
	}
	if(cnt==0)
	printf("\n No such book \n");
}

void count_book()
{
	printf("\n Total no of book in library =%d",count);
}

Output :
1:Enter the book info

2:Display book info

3:Book author

4:Count book

5:Exit

Enter the choice
1

Enter the detail of book

Enter accession number of book =

Enter the book title=life of pie

Enter the name of author=jk

Enter the cost of book=1200

1:Enter the book info

2:Display book info

3:Book author

4:Count book

5:Exit

Enter the choice
2

Detail of 1 booksin library
55
life of pie
jk
1200
1:Enter the book info

2:Display book info

3:Book author

4:Count book

5:Exit

Enter the choice
4

Total no of book in library =1

Leave a comment
Recent Comments
No Comments