Introduction
A library system combines a catalogue with state that changes over time: books move between available and issued, due dates pass and fines accrue. This version simulates the calendar with a day counter so behaviour is deterministic and testable.
Problem statement
Objectives
- Model state transitions (available ↔ issued) with validation
- Implement case-insensitive substring search
- Write and parse a delimited text format
- Separate business rules from the user interface
Features
- Auto-incrementing book IDs
- Issue/return with clear error codes
- Late fines computed from loan length
- Overdue report
- Pipe-separated text storage so titles may contain commas
Concepts demonstrated
- Structs and arrays
- Return-code error handling
- Parsing delimited text
- Simulated time
System architecture
Each module pairs a header (.h, the interface) with a source file (.c, the implementation); main.c contains only the user interface. library.c implements the rules and storage; functions return 1/0/−1 codes that main.c turns into messages. The catalogue is a fixed array inside a static Library (kept off the stack because it is large). Each book is one line: id|title|author|year|issued|member|issue_day.
Folder structure
Complete source code
Makefile
What each file does
- src/library.h
BookandLibrarytypes, loan constants and the API.- src/library.c
- Add/find/issue/return/search rules, case-insensitive matching and the text-file format.
- src/main.c
- Menu, the current-day counter and report printing.
- Makefile
- Build automation:
makebuilds./app,make testruns the sample session and compares it with the expected output,make cleanremoves build files.
How to run it
Build
Run
Test against the expected output
Expected output
Generated by running the project with tests/sample-input.txt. Your output should match tests/expected-output.txt exactly.
1 1 The C Programming Language Kernighan and Ritchie 1988 1 Clean Code Robert Martin 2008 1 Introduction to Algorithms Cormen et al. 2009 4 1001 Priya 4 1001 Rahul 4 1003 Rahul 7 10 5 1003 7 10 6 5 1001 3 clean 2 0
Testing
- Diff the sample run against
tests/expected-output.txt(includes an already-issued error, an on-time return and a late return with a Rs 12 fine). - Open library.txt in a text editor after a run and check its format.
- Restart the program and confirm issued books are still issued.
Common errors
Titles cut off at a comma after reload
Use the | separator (as this project does); commas are common in titles.
Fine is negative
Only charge for days beyond the loan period: late > 0 ? late * FINE_PER_DAY : 0.
Possible improvements
- Add members with borrowing limits
- Reserve books that are currently issued
- Use real dates with <time.h>
Additional challenges
- 1Limit each member to 3 books at a time.
- 2Add a report of the five most borrowed books (track an issue count).
- 3Store the catalogue in a binary file with random-access updates.
Built and tested it yourself? Mark it to update your dashboard.