Skip to content
 
 

Repository files navigation

Library Management System

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.

Overview

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.

Features

Book management

  • 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

User management

  • Add, update, and deactivate users
  • Search by first name, last name, or email
  • List all users
  • View a user's full loan history

Loan management

  • 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

Statistics

  • Counts of active books, active users, active loans, and overdue loans
  • Catalog size
  • Most-borrowed book and most-active user

Data model

Data is stored in pipe-delimited (|) text files under data/.

data/books.txt

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

data/users.txt

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

data/loans.txt

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.

How it works

  1. On startup, main() initializes three dynamic arrays (BookArray, UserArray, LoanArray) and loads records from the files in data/.
  2. The menu loop (runMainMenu) dispatches to book, user, loan, statistics, and save actions.
  3. The arrays grow automatically via realloc as records are added.
  4. On save/exit, dumpAll rewrites all three data files from memory.

Build

The project uses the standard C library only (stdio, stdlib, string, ctype, time). Compile with gcc:

gcc main.c -o main.exe

Run

Run from the project root so the relative data/ paths resolve correctly:

./main.exe

Helper script

reorganize.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.py

Project structure

main.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

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages