0% found this document useful (0 votes)
10 views5 pages

24P01258-Subash R-c program[1]

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

24P01258-Subash R-c program[1]

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Student Register Number: 24P01258 Student

Name: Subash R.
Course:MCA
Subject : C Programming
Class & Section: 1st MCA D sec

Thisis to certify that smt/sri Subash R has satisfactorily completed the course of
assignment/seminar/presentation/case studies prescribed by the Presidency College
(Autonomous) for the semester 1ST MCA degree course in the year 2025 -2026

MARKS

MAX OBTAINED

Subash R
Signature of the Student Signature of the Staff Member

Library Management System


Library management system is a simple console application using linked list in C programming
language. User can perform basic library management operations like issuing books, returning the
issued books and displaying records of the issued books with the user details.

The provided code is a simple Library Management System in C. Here are some possible errors or
issues that coders might encounter with this code, along with their solutions:

1. Input Buffer Issues

Problem:
The getchar() function is used to clear the input buffer before reading the book name with fgets().
However, if there are additional characters in the buffer (e.g., after entering a number for the menu),
they might cause unexpected behavior.

Solution:
Use a loop to ensure the input buffer is fully cleared:
c
Copy code while

(getchar() != '\n');

2. Case Sensitivity in Book Names

Problem:
The strcmp() function performs a case-sensitive comparison. If a user enters a book name with
different capitalization, the program will not recognize it.

Solution:
Convert both the input and the stored book names to lowercase before comparison. Use tolower()
from <ctype.h>:

c
Copy code

#include <ctype.h>

void to_lowercase(char *str) {


for (int i = 0; str[i]; i++) {

str[i] = tolower(str[i]);

}
}

// Example usage before comparing strings:


to_lowercase(book_name);
to_lowercase(books[i].title);

3. Truncation of Long Book Titles

Problem:
If a book title exceeds 50 characters, it will be truncated, potentially causing mismatches.
Solution:
Increase the size of the title array in the Book structure. For example:

Copy code
char title[100];

Alternatively, use dynamic memory allocation if you expect titles to vary significantly in length.

4. Incorrect Menu Choices

Problem:
If the user enters a non-integer value for the menu choice, the program may enter an infinite loop.

Solution:
Validate user input using scanf() return value:
c

Copy code if (scanf("%d", &choice) != 1) {

printf("Invalid input. Please enter a

number.\n"); while

(getchar() != '\n'); // Clear invalid input continue;


}

5. Duplicate Book Titles

Problem:
If the library contains books with the same title, the program will always operate on the first match.

Solution:
Ensure that book titles are unique. Alternatively, enhance the structure to include additional identifiers
(e.g., int book_id) to uniquely identify each book.
6. No Handling of Empty Library

Problem:
If the library is empty, functions like display_books() will not indicate that no books exist.
Solution:
Add an explicit check for an empty library:
c

Copy code

if (count == 0) { printf("\nThe library is currently

empty.\n"); return;

7. Books Not Found in Library

Problem:
The program does not account for scenarios where a user repeatedly tries to issue or return a
nonexistent book.
Solution:
No changes are required, but ensure that the error message clearly communicates the issue:
c

Copy code printf("\n'%s' is not recognized by the library.\n", book_name);

8. Fixed Book Array Size


Problem:
The library is initialized with a fixed number of books. If more books need to be added, the array size
is insufficient.

Solution:
Use dynamic memory allocation with malloc() and realloc() to allow resizing of the books array at
runtime.

9. Memory Leak Potential

Problem:
If dynamic memory allocation is introduced, forgetting to free allocated memory can lead to memory
leaks.

Solution:
Use free() to release memory before the program exits.

10. Infinite Loop on Invalid Input


Problem:
If the user enters invalid input repeatedly, the program will not terminate.
Solution:
Provide an option to exit gracefully on repeated invalid input, or limit retries:
c

Copy code int

retries = 3; while

(retries-- > 0) {
// Handle invalid input

By addressing these potential issues, the program can be made more robust and user-friendly.

You might also like