c code for library system

  • clibrary
  • write a code for library management system

    Let us work on the menu of a library. Create a structure containing book information like accession number, name of author, book title and flag to know whether book is issued or not. Create a menu in which the following can be done. A.- Display book information B- Add a new book C - Display all the books in the library of a particular author D - Display the number of books of a particular title E - Display the total number of books in the library F- Issue a book (If we issue a book, then its number gets decreased by 1 and if we add a book, its number gets increased by 1).

    Code

    #include <stdio.h> #include <string.h> int total_book = 0; int total = 0; typedef struct book { char name_of_author[50]; char book_title[50]; int flag; } bo; void display(bo *x) { for (int i = 0; i < total_book; i++) { printf("book title: %s\n", x[i].book_title); printf("book author: %s\n", x[i].name_of_author); printf("issued, 0-> no ,1-> yes: %d\n", x[i].flag); } } void display_author(bo *x, char *check) { for (int i = 0; i < total_book; i++) { if (strcmp(check, x[i].name_of_author)) { printf("book title: %s\n", x[i].book_title); printf("book title: %s\n", x[i].name_of_author); printf("issued, 0-> no ,1-> yes: %d\n", x[i].flag); } } } void display_title(bo *x, char *check) { for (int i = 0; i < total_book; i++) { if (strcmp(check, x[i].book_title)) { printf("book title: %s\n", x[i].book_title); printf("book title: %s\n", x[i].name_of_author); printf("issued, 0-> no ,1-> yes: %d\n", x[i].flag); } } } void add(bo *x) { getchar(); printf("enter the name of book\n"); gets(x[total_book].book_title); printf("enter the name of author\n"); gets(x[total_book].name_of_author); x->flag = 0; total_book++; total++; printf("book added\n"); } void issue(bo *x, char *check) { for (int i = 0; i < total_book; i++) { if (strcmp(check,x[i].name_of_author) || strcmp(check,x[i].book_title)) { x[i].flag = 1; printf("book issued\n"); total--; } } } int main() { int l, n; bo library[100]; char cc[50]; do { printf("select what you want,enter the number\n"); printf("1->to display\n"); printf("2->to display by author\n"); printf("3->to display by title\n"); printf("4->toatl of number of books in library\n"); printf("5->issue a book\n"); printf("6->add book\n"); scanf("%d", &l); switch (l) { case 1: display(library); break; case 2: printf("enetr the name\n"); getchar(); gets(cc); display_author(library, cc); break; case 3: printf("enetr the name\n"); getchar(); gets(cc); display_title(library, cc); break; case 4: printf("total number of books: %d\n", total); break; case 5: printf("enetr the name\n"); getchar(); gets(cc); issue(library, cc); break; case 6: add(library); display(library); break; default: printf("invalid\n"); } printf("enter 1 to go menu or 0 to exit\n"); scanf("%d", &n); } while (n); return 0; }