Awesome Quiz Game Project using C

Simple Library Management System Project in C Language

Simple Library Management System Project in C Language

Overview of Library Management System Project

The Library Management System using C. This project is based on a console base application without graphics. In this Simple Library Management System, you can perform functions such as adding new books, returning books, issuing books, deleting records of books issued, viewing records of books issued, searching for book information, and more. File handling has been used in this project for almost all functions.

This application is based on file handling in C, where I have used file-related functions like fopen, fread, fwrite, ..etc. Good thing is that the “Library management system project” is password-protected, so only authorized persons are able to login into this application. Simple Phone Book Management System project in C

About Library Management System Project in C:

For the library management system, this project considers six departments – Computer, Electrical, Civil, Electronics, Mechanical, and Architecture. you can change them at any time if you have more experience in C language.

These departments work simultaneously with the operations mentioned given above. You can add a book to the Civil section, delete a book from the Electrical section, or view issued book details of the Mechanical department at any time.

Awesome Quiz Game Project using C

These are the functions used in this Library Management system Project:

void mainmenu(void) – This function is used to display the main menu of this Library project.

void returnfunc(void) – Inside this function, the main menu function is called when the user presses a key. With this, the user can go back to the main menu.

void addbooks(void) – This function adds books to a file. For that, you need to mention the department to where you want to add the book. The record is saved in a file. And, it is the same for the following functions.
void deletebooks(void)
void editbooks(void)
void searchbooks(void)
void issuebooks(void)
void viewbooks(void)

void issuerecord() – This Function is used to keep record of the student to whom the book has been issued.

void closeapplication(void) – This function is used for closing the application.

int getdata() – This function is used to asks for data input from the user.

int checkid(int) – This function is used to check whether the ID of a book entered by a user exists in the file or not.

void Password() – In this function, the user is asked to input a password to run the application after it is opened.

void gotoxy (int x, int y) – You need to understand this function as it is one of the most important ones used in this project. This function allows you to print text in any place on the screen. you can use this directly in Turbo C.

delay(unsigned int mseconds) – This function delays the execution of project.

Source Code Of Library Management System Project

#include<stdio.h>
#include<stdlib.h>
#include<time.h>

struct books{
    int id;
    char bookName[50];
    char authorName[50];
    char date[12];
}b;

struct student{
    int id;
    char sName[50];
    char sClass[50];
    int sRoll;
    char bookName[50];
    char date[12];
}s;

FILE *fp;

int main(){

    int ch;

    while(1){
        system("cls");
        printf("<== Library Management System ==>\n");
        printf("1.Add Book\n");
        printf("2.Books List\n");
        printf("3.Remove Book\n");
        printf("4.Issue Book\n");
        printf("5.Issued Book List\n");
        printf("0.Exit\n\n");
        printf("Enter your choice: ");
        scanf("%d", &ch);

        switch(ch){
        case 0:
            exit(0);

        case 1:
            addBook();
            break;

        case 2:
            booksList();
            break;

        case 3:
            del();
            break;

        case 4:
            issueBook();
            break;

        case 5:
            issueList();
            break;

        default:
            printf("Invalid Choice...\n\n");

        }
        printf("Press Any Key To Continue...");
        getch();
    }

    return 0;
}


void addBook(){
    char myDate[12];
    time_t t = time(NULL);
    struct tm tm = *localtime(&t);
    sprintf(myDate, "%02d/%02d/%d", tm.tm_mday, tm.tm_mon+1, tm.tm_year + 1900);
    strcpy(b.date, myDate);

    fp = fopen("books.txt", "ab");

    printf("Enter book id: ");
    scanf("%d", &b.id);

    printf("Enter book name: ");
    fflush(stdin);
    gets(b.bookName);

    printf("Enter author name: ");
    fflush(stdin);
    gets(b.authorName);

    printf("Book Added Successfully");

    fwrite(&b, sizeof(b), 1, fp);
    fclose(fp);
}


void booksList(){

    system("cls");
    printf("<== Available Books ==>\n\n");
    printf("%-10s %-30s %-20s %s\n\n", "Book id", "Book Name", "Author", "Date");

    fp = fopen("books.txt", "rb");
    while(fread(&b, sizeof(b), 1, fp) == 1){
        printf("%-10d %-30s %-20s %s\n", b.id, b.bookName, b.authorName, b.date);
    }

    fclose(fp);
}

void del(){
    int id, f=0;
    system("cls");
    printf("<== Remove Books ==>\n\n");
    printf("Enter Book id to remove: ");
    scanf("%d", &id);

    FILE *ft;

    fp = fopen("books.txt", "rb");
    ft = fopen("temp.txt", "wb");

    while(fread(&b, sizeof(b), 1, fp) == 1){
        if(id == b.id){
            f=1;
        }else{
            fwrite(&b, sizeof(b), 1, ft);
        }
    }

    if(f==1){
        printf("\n\nDeleted Successfully.");
    }else{
        printf("\n\nRecord Not Found !");
    }

    fclose(fp);
    fclose(ft);

    remove("books.txt");
    rename("temp.txt", "books.txt");

}


void issueBook(){

    char myDate[12];
    time_t t = time(NULL);
    struct tm tm = *localtime(&t);
    sprintf(myDate, "%02d/%02d/%d", tm.tm_mday, tm.tm_mon+1, tm.tm_year + 1900);
    strcpy(s.date, myDate);

    int f=0;

    system("cls");
    printf("<== Issue Books ==>\n\n");

    printf("Enter Book id to issue: ");
    scanf("%d", &s.id);

    //Check if we have book of given id
    fp = fopen("books.txt", "rb");

    while(fread(&b, sizeof(b), 1, fp) == 1){
        if(b.id == s.id){
            strcpy(s.bookName, b.bookName);
            f=1;
            break;
        }
    }

    if(f==0){
        printf("No book found with this id\n");
        printf("Please try again...\n\n");
        return;
    }

    fp = fopen("issue.txt", "ab");

    printf("Enter Student Name: ");
    fflush(stdin);
    gets(s.sName);

    printf("Enter Student Class: ");
    fflush(stdin);
    gets(s.sClass);

    printf("Enter Student Roll: ");
    scanf("%d", &s.sRoll);

    printf("Book Issued Successfully\n\n");

    fwrite(&s, sizeof(s), 1, fp);
    fclose(fp);
}

void issueList(){
    system("cls");
    printf("<== Book Issue List ==>\n\n");

    printf("%-10s %-30s %-20s %-10s %-30s %s\n\n", "S.id", "Name", "Class", "Roll", "Book Name", "Date");

    fp = fopen("issue.txt", "rb");
    while(fread(&s, sizeof(s), 1, fp) == 1){
        printf("%-10d %-30s %-20s %-10d %-30s %s\n", s.id, s.sName, s.sClass, s.sRoll, s.bookName, s.date);
    }

    fclose(fp);
}