MICROPROJECT ON
LIBRARY MANAGEMENT SYSTEM
Design project report submitted in partial fulfillment of the requirements
for the award of the degree of
Bachelor of Technology
in
Computer Science & Engineering
Submitted by
Alan Saju
Aleena Treesa
Nazal
College of Engineering Poonjar (CEP)
POONJAR-686584
Affiliated to
APJ ABDUL KALAM TECHNOLOGICAL UNIVERSITY
KERALA
College of Engineering Poonjar (CEP)
Poonjar (P.O), Kottayam-686584
CERTIFICATE
This is to certify that project report entitled “Library Management System” is a
bonafide report presented during V th semester by Alan, Aleena and Nazal, in
partial fulfillment of the requirements for the award of the degree of Bachelor of
Technology (B.Tech) in Computer Science & Engineering.
Rajesh K R
Head of the Department
ABSTRACT
This project report presents the design and implementation of a Library Management System (LMS) using the
C programming language. The system allows for efficient management of library resources, including the addition
of new books, tracking available copies, issuing books to students, managing returns, and maintaining a record
of issued books. The primary objectives of the project were to create a user-friendly interface for library staff,
automate book-related processes, and provide accurate records of transactions.
The system comprises two main entities: books and students, represented as structures in the C program.
A file-based approach is employed for persistent data storage, with separate files for storing book information
("books.dat") and issued book transactions ("issue.dat"). The project incorporates essential functionalities, such
as adding books to the library, listing available books, issuing books to students, managing returns, and
displaying an issue list.
The implementation employs fundamental C programming concepts, file handling, and data structures to
achieve the desired functionalities. The program provides a simple and intuitive command-line interface for
users, offering a menu-driven approach for easy navigation.
ACKNOWLEDGMENT
Whenever a module of work is completed successfully, a source of inspiration and guidance is always
there for the student. We hereby take the opportunity to thank those entire people who helped us in
many different ways.
First and foremost we thank Almighty God who gave us the inner strength, resource and ability to complete
our project successfully, without which all our efforts would have been in vain. We derive immense pleasure
in expressing our sincere thanks to the principal Dr.Jobymol Jacob , for the kind co-operation in all aspects
of this project. We express our gratitude to Prof. Rajesh K.R, HOD, Department of Computer Science and
Engineering for his kind cooperation in all aspects of this project. we would like to express our sincere
gratitude to the project guide and coordination for his patience, motivation, enthusiasm and immense
knowledge which helped us to successfully complete this project.
We are indebted to our beloved teachers for their co-operation and suggestions throughout the project
which helped us a lot. We also thank all our friends and classmates for their interest, dedication and
encouragement shown towards the project. We convey hearty thanks to our parents for their moral support,
suggestion and encouragement to make this venture a successfull.
CONTENTS
1. DESIGN DETAILS
2.MODULE DESCRIPTION
4. FLOWCHART
5.PROGRAM
5. SCREENSHOTS
6. CONCLUSION
DESIGN DETAILS
1. Struct Definitions:
Student Struct (`struct student`):
- `int id`: Student ID.
- `char sName[50]`: Student name.
- `char sClass[50]`: Student class.
- `int sRoll`: Student roll number.
- `char bookName[50]`: Name of the book issued to the student.
Books Struct (`struct books`):
- `int id`: Book ID.
- `char bookName[50]`: Book name.
- `char authorName[50]`: Author's name.
- `int count`: Number of available copies of the book.
2. File Handling:
The program uses file handling to store information about books (`books.dat`) and issued books
(`issue.dat`).
3. Functions:
`addBook()` Function:
- Opens `books.dat` in append binary mode.
- Accepts input for book details (id, name, author, count) from the user.
- Writes the book information to the file.
`booksList()` Function:
- Displays a list of available books from the `books.dat` file.
`issueBook()` Function:
- Accepts a book ID from the user.
- Checks if the book is available.
- If available, decrements the book count and records the student details in the `issue.dat` file.
`returnBook()` Function:
- Accepts a student roll number and book ID from the user.
- Displays books issued to the specified student.
- If the book is returned, increments the book count and updates the `books.dat` file.
- Updates the `issue.dat` file.
`issueList()` Function:
- Displays a list of books issued to students from the `issue.dat` file.
4. Menu-Driven Interface (`main()` Function):
- A menu-driven interface allows the user to choose from various options:
1. Add Book
2. Books List
3. Issue Book
4. Issued Book List
5. Return Book
6. Exit
5. User Input and Output:
- Uses `printf()` and `scanf()` for user prompts and input.
- Display messages to inform the user about the success or failure of operations.
6. Looping:
- The program runs in an infinite loop until the user chooses to exit (`case 6`).
7. Error Handling:
- Checks for file opening errors.
- Validates user inputs in some cases.
- Displays appropriate error messages.
8. Modularity:
- Functions are used to modularize the code, making it more readable and maintainable.
9. Clearing Screen:
- Uses `system("cls")` to clear the console screen.
10. Non-Standard Libraries:
- Uses `conio.h` for clearing the screen and `getch()` for pausing execution. Note that these are non-
standard and platform-dependent.
11. Platform Independence:
- Some operations, such as clearing the screen, might not be platform-independent.
12. Magic Numbers:
- Replace magic numbers with named constants for better code readability.
13. Comments:
- There are comments throughout the code to explain the purpose of different sections.
14. Input Buffer:
- Uses `fflush(stdin)` for clearing the input buffer, which is not recommended. Consider alternative
methods.
MODULE- WISE DESCRIPTION
Data Structures:
Two structures are defined: struct student for student information and struct books for book information.
The program uses a global file pointer fp to handle file operations.
addBook() Function:
Adds a book to the library system.
Takes input for book details such as ID, name, author, and count.
Appends the book information to the "books.dat" file.
booksList() Function:
Displays a list of available books.
Reads book information from the "books.dat" file and prints it on the console.
issueBook() Function:
Handles the process of issuing a book to a student.
Checks if the specified book is available.
If available, decreases the count of available copies, adds student information, and appends the record to
the "issue.dat" file.
returnBook() Function:
Manages the return of a book by a student.
Displays books issued to a specific student based on their roll number.
Takes input for the book to be returned and updates the count of available copies.
issueList() Function:
Displays a list of issued books with student details.
Reads information from the "issue.dat" file and prints it on the console.
main() Function:
The main function provides a menu-driven interface for users.
Options include adding a book, listing books, issuing a book, listing issued books, returning a book, and
exiting the program.
Menu Options:
Users can interact with the program by choosing options from the menu.
Each option corresponds to a specific function in the program.
Infinite Loop:
The program runs in an infinite loop, allowing users to perform multiple operations without restarting.
File Handling:
The program uses file operations (fopen, fwrite, fread, fclose) to store and retrieve book and student
information.
FLOWCHART
PROGRAM CODE
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
struct student {
int id;
char sName[50];
char sClass[50];
int sRoll;
char bookName[50];
} s;
struct books {
int id;
char bookName[50];
char authorName[50];
int count; // added count for each book
} b;
FILE *fp;
void addBook() {
fp = fopen("books.dat", "ab");
printf("Enter book id: ");
scanf("%d", &b.id);
printf("Enter book name: ");
fflush(stdin);
fgets(b.bookName, sizeof(b.bookName), stdin);
b.bookName[strcspn(b.bookName, "\n")] = '\0'; // Remove the newline character
printf("Enter author name: ");
fflush(stdin);
fgets(b.authorName, sizeof(b.authorName), stdin);
b.authorName[strcspn(b.authorName, "\n")] = '\0'; // Remove the newline character
printf("Enter the number of copies: ");
scanf("%d", &b.count);
printf("Book Added Successfully\n");
fwrite(&b, sizeof(b), 1, fp);
fclose(fp);
}
void booksList() {
system("cls");
printf("<== Available Books ==>\n\n");
printf("%-10s %-30s %-20s %-10s\n", "Book id", "Book Name", "Author", "Count");
fp = fopen("books.dat", "rb");
while (fread(&b, sizeof(b), 1, fp) == 1) {
printf("%-10d %-30s %-20s %-10d\n", b.id, b.bookName, b.authorName, b.count);
}
fclose(fp);
}
void issueBook() {
int f = 0;
system("cls");
printf("<== Issue Books ==>\n\n");
printf("Enter Book id to issue: ");
scanf("%d", &s.id);
// Check if we have a book of the given id
fp = fopen("books.dat", "rb+");
if (fp == NULL) {
printf("Error opening books.dat\n");
return;
}
while (fread(&b, sizeof(b), 1, fp) == 1) {
if (b.id == s.id && b.count > 0) {
strcpy(s.bookName, b.bookName);
f = 1;
break;
}
}
if (f == 0) {
fclose(fp);
if (b.count == 0) {
printf("No copies available for this book\n");
} else {
printf("No book found with this id\n");
}
printf("Please try again...\n\n");
return;
}
// Decrease the count of available copies
b.count--;
fseek(fp, -sizeof(b), SEEK_CUR);
fwrite(&b, sizeof(b), 1, fp);
fclose(fp);
// Append the record to the issue.dat file
fp = fopen("issue.dat", "ab");
if (fp == NULL) {
printf("Error opening issue.dat\n");
return;
}
printf("Enter Student Name: ");
fflush(stdin);
fgets(s.sName, sizeof(s.sName), stdin);
s.sName[strcspn(s.sName, "\n")] = '\0'; // Remove the newline character
printf("Enter Student Class: ");
fflush(stdin);
fgets(s.sClass, sizeof(s.sClass), stdin);
s.sClass[strcspn(s.sClass, "\n")] = '\0'; // Remove the newline character
printf("Enter Student Roll: ");
scanf("%d", &s.sRoll);
fwrite(&s, sizeof(s), 1, fp);
fclose(fp);
printf("Book Issued Successfully\n\n");
}
void returnBook() {
int rollNo, bookId, f = 0;
system("cls");
printf("<== Return Books ==>\n\n");
printf("Enter Student Roll No: ");
scanf("%d", &rollNo);
FILE *fr; // File pointer for reading issue.dat
FILE *fw; // File pointer for writing temp.dat
fr = fopen("issue.dat", "rb");
if (fr == NULL) {
printf("Error opening issue.dat\n");
return;
}
fw = fopen("temp.dat", "wb");
if (fw == NULL) {
printf("Error opening temp.dat\n");
fclose(fr);
return;
}
printf("Books issued to student with Roll No %d:\n", rollNo);
printf("%-10s %-30s %-10s\n", "Book id", "Book Name", "Author");
while (fread(&s, sizeof(s), 1, fr) == 1) {
if (rollNo == s.sRoll) {
printf("%-10d %-30s %-10s\n", s.id, s.bookName, s.sName);
f = 1;
} else {
fwrite(&s, sizeof(s), 1, fw);
}
}
fclose(fr);
if (f == 0) {
printf("\n\nNo books found for the specified Roll No.\n");
remove("temp.dat"); // Delete the temporary file if no record is found
return;
}
fclose(fw);
printf("\nEnter Book id to return: ");
scanf("%d", &bookId);
fr = fopen("issue.dat", "rb");
if (fr == NULL) {
printf("Error opening issue.dat\n");
return;
}
fw = fopen("temp.dat", "wb");
if (fw == NULL) {
printf("Error opening temp.dat\n");
fclose(fr);
return;
}
f = 0; // Reset the flag for reuse
while (fread(&s, sizeof(s), 1, fr) == 1) {
if (bookId == s.id && rollNo == s.sRoll) {
printf("Book returned by %s\n", s.sName);
f = 1;
// Update the count in "books.dat"
fp = fopen("books.dat", "rb+");
if (fp == NULL) {
printf("Error opening books.dat\n");
fclose(fw);
return;
}
while (fread(&b, sizeof(b), 1, fp) == 1) {
if (bookId == b.id) {
b.count++;
fseek(fp, -sizeof(b), SEEK_CUR);
fwrite(&b, sizeof(b), 1, fp);
break;
}
}
fclose(fp);
} else {
fwrite(&s, sizeof(s), 1, fw);
}
}
fclose(fr);
fclose(fw);
if (f == 0) {
printf("\n\nBook not found for the specified Book id and Roll No.\n");
remove("temp.dat"); // Delete the temporary file if no record is found
return;
}
remove("issue.dat");
rename("temp.dat", "issue.dat");
printf("Press Any Key To Continue...");
getch();
}
void issueList() {
system("cls");
printf("<== Book Issue List ==>\n\n");
printf("%-10s %-30s %-20s %-10s\n", "S.id", "Name", "Class", "Roll");
fp = fopen("issue.dat", "rb");
if (fp == NULL) {
printf("Error opening issue.dat\n");
return;
}
while (fread(&s, sizeof(s), 1, fp) == 1) {
printf("%-10d %-30s %-20s %-10d\n", s.id, s.sName, s.sClass, s.sRoll);
}
fclose(fp);
}
int main() {
int ch;
while (1) {
system("cls");
printf("<== Library Management System ==>\n");
printf("1.Add Book\n");
printf("2.Books List\n");
printf("3.Issue Book\n");
printf("4.Issued Book List\n");
printf("5.Return Book\n");
printf("6.Exit\n\n");
printf("Enter your choice: ");
scanf("%d", &ch);
switch (ch) {
case 0:
exit(0);
case 1:
addBook();
break;
case 2:
booksList();
break;
case 3:
issueBook();
break;
case 4:
issueList();
break;
case 5:
returnBook();
break;
default:
printf("Invalid Choice...\n\n");
}
printf("Press Any Key To Continue...");
getch();
}
return 0;
}
SAMPLE SCREENSHOTS
CONCLUSION
This website provides a computerized version of library management system which
will benefit the students as well as the staff of the library. It makes entire process online
where admin can easily create necessary changes on student and book details easily. It
contains student panel and book panel which makes the implementation much more easier
and faster.
There is a future scope of this facility that many more features such as online lectures
video tutorials can be added by teachers as well as online assignments submission facility , a
feature of group chat where students can discuss various issues of engineering can be added
to this project thus making it more interactive more user friendly and project which fulfills
each users need in the best way possible.