You are on page 1of 10

LIBRARY MANAGEMENT

SYSTEM

Submitted by
Chinmay Paradkar
Yogesh Mahajan
ABSTRACT

This Library Management Application is developed


to make the task of searching the library books
easier. We have developed the books vs. authors’
database with MySQL and we have tried to develop
its connectivity with C. This project is based on the
library management system where adding a book to
the file, searching the book according to the author,
displaying all the information of books, book id is
shown and used here. A simple and efficient C code
for file management is used to do this project.
CODE
#include<stdio.h>
void addbook();
void searchbook();
void author();
void display();
char in[1000];
struct
{
int id;
char name[50];
char author[50];
}book;

FILE *record;

void main()
{
int choice;
printf("Library management project");
do
{
printf("\n\tMENU\n 1> Add A New Book\n 2> Search a book \n 3> Display Complete
Information\n 4> Display All Books of An Author\n 0> Exit the program\n\n\t Enter your
choice (1-10): ");
scanf("%d",&choice);
switch (choice)
{
case 1:
addbook();
break;
case 2:
searchbook();
break;
case 3:
display();
break;
case 4:
author();
break;
}
}while(choice!=0);
}
void addbook()
{
record=fopen("abcda.txt","a+");
printf("Enter the book ID");
scanf("%d",&book.id);
printf("Enter the book name");
scanf("%s",&book.name);
printf("Enter the name of author");
scanf("%s",&book.author);
fprintf(record,"\n%d\t%s\t%s\t",book.id,book.name,book.author);
printf("A NEW BOOK IS ADDED SUCCESFULLY");
fclose(record);
}
void searchbook()
{
char find[25];
int Found=0;
if((record=fopen("abcda.txt","r"))==NULL)
printf(" The File is Empty...\n\n");
else
{
printf("\nEnter The Name Of Book : ");
scanf("%s",&find);
while(!feof(record)&& Found==0)
{
fscanf(record,"%d %s %s", &book.id,book.name,book.author);
if(strcmp(find,book.name)==0)
{ Found=1;}
}
if(Found)
{
printf("\nThe Unique ID of The Book: %d\nThe Name of Book is: %s\nThe Author is:
%s\n\n",book.id,book.name,book.author);
}
else if(!Found)
printf("There is no such Entry...\n");
fclose(record);
}
}

void author()
{
int i;
char Target[500];
int Found=0;
if((record=fopen("abcda.txt","r"))==NULL)
printf(" ! The file is empty... \n\n");
else
{
printf("\nEnter The Name Of Author : ");
scanf("%s",&Target);
printf("\nBooks:");
while(!feof(record))
{
fscanf(record,"%d %s %s",&book.id,book.name,book.author);
if(strcmp(Target,book.author)==0)
{
Found=1;
printf("\n\t%s",book.name);
}

}
if(!Found)
printf(" There is no such Entry...\n");
fclose(record);
}

}
void display()
{
record = fopen("abcda.txt","a+");
printf("\nBookid\tName\tAuthor\n",in);
do
{
fgets(in,50,record);
printf("%s\n",in);
}while(!feof(record));
fclose(record);
}
OUTPUT
Library management project
MENU
1> Add A New Book
2> Search a book
3> Display Complete Information
4> Display All Books of An Author
5> Exit the program

Enter your choice (1-5): 1


Enter the book ID:34
Enter the book name:ABC
Enter the name of author:CHINMAY
A NEW BOOK IS ADDED SUCCESFULLY
MENU
1> Add A New Book
2> Search a book
3> Display Complete Information
4> Display All Books of An Author
5> Exit the program

Enter your choice (1-5): 1


Enter the book ID:23
Enter the book name:DEF
Enter the name of author:YOGESH
A NEW BOOK IS ADDED SUCCESFULLY
MENU
1> Add A New Book
2> Search a book
3> Display Complete Information
4> Display All Books of An Author
5> Exit the program

Enter your choice (1-5): 1


Enter the book ID:23
Enter the book name:DDB
Enter the name of author:CHINMAY
A NEW BOOK IS ADDED SUCCESFULLY
MENU
1> Add A New Book
2> Search a book
3> Display Complete Information
4> Display All Books of An Author
5> Exit the program

Enter your choice (1-5): 2

Enter The Name Of Book : SE

The Unique ID of The Book: 67


The Name of Book is: SE
The Author is: MAHAJAN

MENU
1> Add A New Book
2> Search a book
3> Display Complete Information
4> Display All Books of An Author
5> Exit the program
Enter your choice (1-5): 3

Bookid Name Author

34 ABC CHINMAY

23 DEF YOGESH

67 SE MAHAJAN

67 DDB CHINMAY

45 SPCC CHINMAY

MENU
1> Add A New Book
2> Search a book
3> Display Complete Information
4> Display All Books of An Author
5> Exit the program

Enter your choice (1-5): 1


Enter the book ID:45
Enter the book name:SPCC
Enter the name of author:CHINMAY
A NEW BOOK IS ADDED SUCCESFULLY
MENU
1> Add A New Book
2> Search a book
3> Display Complete Information
4> Display All Books of An Author
5> Exit the program

Enter your choice (1-5): 4

Enter The Name Of Author : CHINMAY

Books:
ABC
SPCC
DDB
1> Add A New Book
2> Search a book
3> Display Complete Information
4> Display All Books of An Author
5> Exit the program

Enter your choice (1-5):5

You might also like