A console-based library management system written in C. It manages books, users,
and loans, with data persisted to plain-text files in the data/ directory.
The application (main.c) presents a text menu that lets a librarian manage a catalog of books, a list of registered users, and the loans that link them. All data is loaded from disk at startup, edited in memory during the session, and written back to disk on save/exit.
- Add, update, and deactivate books
- Search by title, author, or category (case-insensitive substring match)
- List all books with availability and loan counts
- Sort the catalog by title, author, or year
- Add, update, and deactivate users
- Search by first name, last name, or email
- List all users
- View a user's full loan history
- Create a loan (decrements available copies, sets a 14-day due date)
- Return a book (records the return date, restores availability)
- List active loans
- List overdue loans
- Counts of active books, active users, active loans, and overdue loans
- Catalog size
- Most-borrowed book and most-active user
Data is stored in pipe-delimited (|) text files under data/.
id|title|author|category|year|isbn|total_qty|available_qty|total_loans|is_active
Example:
1|Il nome della rosa|Umberto Eco|Romanzo|1980|9780000000001|3|2|1|1
id|first_name|last_name|phone|email|max_loans|total_loans|is_active
Example:
1|Mario|Rossi|3331234567|mario.rossi@email.it|3|1|1
id|user_id|book_id|loan_date|due_date|return_date|is_active
Example:
1|1|1|2026-06-01|2026-06-15||1
Dates use the YYYY-MM-DD format. An empty return_date means the book is still
on loan.
- On startup,
main()initializes three dynamic arrays (BookArray,UserArray,LoanArray) and loads records from the files indata/. - The menu loop (
runMainMenu) dispatches to book, user, loan, statistics, and save actions. - The arrays grow automatically via
reallocas records are added. - On save/exit,
dumpAllrewrites all three data files from memory.
The project uses the standard C library only (stdio, stdlib, string,
ctype, time). Compile with gcc:
gcc main.c -o main.exeRun from the project root so the relative data/ paths resolve correctly:
./main.exereorganize.py is a maintenance script that reorders
main.c, grouping #include directives, #define macros, and
typedef struct definitions toward the top of the file. It reads and rewrites
main.c in place.
python reorganize.pymain.c # Library management application (C source)
reorganize.py # Script that regroups includes/defines/structs in main.c
data/
books.txt # Book records
users.txt # User records
loans.txt # Loan records