A simple console-based library system written in C for managing a collection of books. The program uses a local text file (books.db) as its database.
- Load and save book records from/to a
books.dbfile - Add new books with details like ISBN, title, authors, year, and genre
- Mark books as borrowed or returned (with date)
- Search for books by ISBN (exact match) or title (partial match)
- If the database file is missing, it will be created automatically
gcc main.c -o library
./libraryThe program will attempt to load books.db. If the file doesn't exist, it will be created when you save data.
When you run the program, a simple text menu appears:
[1]Find the book[2]Add the book[3]Return the book[4]End the program
You can search in two ways:
- By ISBN β must match exactly
- By Title β partial match works (e.g., typing
"The"will return all books with"The"in the title)
If multiple books match your input, youβll be shown a list to pick from:
Books found:
----------------------
1. The C Programming Language
2. The Hobbit
Choose a book by index (0 to cancel): __
Choose option [2] to add a new book to the database. Youβll be asked to enter:
- ISBN
- Title
- Author(s)
- Year
- Genre
After successful entry, the book will be saved in the database for further interactions.
Option [3] lets you return a previously borrowed book. Youβll need to:
- Search for the book by the ISBN-13
- If itβs marked as borrowed, the status will be updated to false and the return date will be reset.
Option [4] exits the program. If youβve made changes (added or returned books), they will be saved automatically to books.db.
The books.db file stores each book on a separate line, with fields separated by |:
ISBN|Title|Authors|Year|Genre|Borrowed (true/false)|Date (DD-MM-YYYY or "-")
Example:
9780131101630|The C Programming Language|Kernighan, Ritchie|1978|Programming|false|-
- Improve whole logic and code structure
- Break code into modules (
db.c,ui.c, etc.) - Improve input validation
- Add more search filters (e.g., by year or genre)
- Enhance menu usability
MIT License β whole project is free to use and modify.