Write a menu driven program in c that shows the working of a library. The menu option should be: - Add book information. - Display book information. - List all books of given author. - List the count of books in library. - Exit. (Using structured array)

//book shop

#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;

void main()
{
int ch;
while(1)
{
clrscr();
{
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);
printf("\n enter the book title=");
scanf("%s",b[count].book_title);
printf("\n enter the name of author=");
scanf("%s",b[count].author);
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=");
scanf("%s",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);
}

4 comments:

  1. I guess there's a mistake in the function void book_auth().
    Just check out the scanf statement.
    Wats name7 `e???? Confused :/

    ReplyDelete
  2. use &name in book_aauth() in scanf function.

    ReplyDelete
  3. i want menu driven calculator program using structure

    ReplyDelete
  4. How can the library be stored as an array of structures in a notepad document? The program as it is does not store the input books and information after they are recorded, so how can I keep that information continuously?

    ReplyDelete