Library management system

Share it Please
Compile and run this code in Turbo c++.submitted by owner of errorless-c.in .

CODE:


/*----------PROGRAMMER: SOJITRA ADARSH H.--------*/
/*----------AGE: 16 years ---------*/
/*----------OWNER OF www.errorless-c.in ----------*/
/*----------E-mail: adarshsojitra7@gmail.com --------*/
/*----------Including Header Files----------*/
/*----------DO NOT COPY THIS PROGRAM FOR COMMERCIAL USE---------*/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>

/*---------------------STRUCTURE--------------------*/

struct book_inf
{
char book_id[10];
char book_name[300];
char book_author[300];
char book_category[300];
char book_prize[20];
}

/*---------------------Declaring Main---------------------*/

main()
{
FILE *dat;
struct book_inf b;
int cho,choin;
char inf,yn,ryn;
struct date d;
clrscr();
getdate(&d);

while(1)        /*--------------------Infinity Loop-------------------*/

{

/*----------------Starting Information----------------*/


printf("\n    ============================Books Library==============================");
printf("         Date: %d/%d/%d",d.da_day,d.da_mon,d.da_year);
printf("\n\n\t\t\t[1] : Enter New Book");
printf("\n\t\t\t[2] : View book info.");
printf("\n\t\t\t[3] : Edit book info.");
printf("\n\t\t\t[4] : Remove book");
printf("\n\t\t\t[5] : Exit");
printf("\n\n\t\t\tEnter Here ---> ");
scanf("%d",&cho);

/*--------------------------------------------*/

/*--------------Switch Choice Entered By user-------------*/

switch(cho)
{

/*--------------------------Case 1------------------------*/

case 1:
while(1)
{
clrscr();
printf("\n    ============================Books Library==============================");
printf("         Date: %d/%d/%d",d.da_day,d.da_mon,d.da_year);
printf("\n\t\t\t    =====Add Window=====");
printf("\n\n\tEnter Book id (Use first characters of words of book name): ");
fflush(stdin);
gets(b.book_id);
if(access(b.book_id)!=-1)
{
printf("\n\tBook already exist!!!");
}
else
{
dat=fopen(b.book_id,"w");
printf("\n\tEnter Book Name: ");
fflush(stdin);
gets(b.book_name);
printf("\n\tEnter Book's Author name: ");
fflush(stdin);
gets(b.book_author);
printf("\n\tEnter Book Category: ");
fflush(stdin);
gets(b.book_category);
printf("\n\tEnter Book Price: ");
fflush(stdin);
gets(b.book_prize);
fprintf(dat,"Book id: %s",b.book_id);
fprintf(dat,"\nBook Name: %s",b.book_name);
fprintf(dat,"\nBook Author: %s",b.book_author);
fprintf(dat,"\nBook Category: %s",b.book_category);
fprintf(dat,"\nBook Price: %s",b.book_prize);
printf("\n\n\tBook Added Successfully!");
fclose(dat);
}
printf("\n\n\tWant to add more books (Y/N): ");
scanf("%c",&yn);
if(yn=='N')
{
printf("\n\tPress any key to quit to main menu......");
getch();
break;
}
else if(yn=='n')
{
printf("\n\tPress any key to quit to main menu......");
getch();
break;
}
}
clrscr();
break;

/*-------------------End of Case 1-----------------------*/

/*----------------------Case 2---------------------------*/

case 2:
while(1)
{
clrscr();
printf("\n    ============================Books Library==============================");
printf("         Date: %d/%d/%d",d.da_day,d.da_mon,d.da_year);
printf("\n\t\t\t    =====View Window=====");
printf("\n\n\tEnter Book id (Use first characters of words of book name): ");
fflush(stdin);
gets(b.book_id);
dat=fopen(b.book_id,"r");
if(dat==NULL)
{
printf("\n\tBook Does not Exist");
printf("\n\n\tPress any key to go to main menu..........");
getch();
clrscr();
break;
}
inf=fgetc(dat);
printf("\n\n--------------------------------------------------------------------------------");
while(inf!=EOF)
{
printf("%c",inf);
inf=fgetc(dat);
}
printf("\n--------------------------------------------------------------------------------");
fclose(dat);
printf("\n\n\tWant to View more books (Y/N): ");
scanf("%c",&yn);
if(yn=='N')
{
printf("\n\tPress any key to quit to main menu......");
getch();
break;
}
else if(yn=='n')
{
printf("\n\tPress any key to quit to main menu......");
getch();
break;
}
}
clrscr();
break;
/*-------------------End of case 2-----------------------*/

/*-----------------------Case 3--------------------------*/

case 3:
while(1)
{
clrscr();
printf("\n    ============================Books Library==============================");
printf("         Date: %d/%d/%d",d.da_day,d.da_mon,d.da_year);
printf("\n\t\t\t    =====Edit Window=====");
printf("\n\n\tEnter Book id (Use first characters of words of book name): ");
fflush(stdin);
gets(b.book_id);
dat=fopen(b.book_id,"r");
if(dat==NULL)
{
printf("\n\tBook Does not Exist");
printf("\n\n\tPress any key to go to main menu..........");
getch();
clrscr();
break;
}
inf=fgetc(dat);
printf("\n\n--------------------------------------------------------------------------------");
printf("CURRENT DATA: \n\n");
while(inf!=EOF)
{
printf("%c",inf);
inf=fgetc(dat);
}
printf("\n--------------------------------------------------------------------------------");
fclose(dat);
dat=fopen(b.book_id,"w+");
printf("\n\tEnter New Book Name: ");
fflush(stdin);
gets(b.book_name);
printf("\tEnter New Book's Author name: ");
fflush(stdin);
gets(b.book_author);
printf("\tEnter New Book Category: ");
fflush(stdin);
gets(b.book_category);
printf("\tEnter Book Price: ");
fflush(stdin);
gets(b.book_prize);
fprintf(dat,"Book id: %s",b.book_id);
fprintf(dat,"\nBook Name: %s",b.book_name);
fprintf(dat,"\nBook Author: %s",b.book_author);
fprintf(dat,"\nBook Category: %s",b.book_category);
fprintf(dat,"\nBook Price: %s",b.book_prize);
printf("\n\tBook Edited Successfully!");
fclose(dat);
printf("\n\n\tWant to Edit more books (Y/N): ");
scanf("%c",&yn);
if(yn=='N')
{
printf("\n\tPress any key to quit to main menu......");
getch();
break;
}
else if(yn=='n')
{
printf("\n\tPress any key to quit to main menu......");
getch();
break;
}
}
clrscr();
break;
/*--------------------End of case 3----------------------*/

/*------------------------Case 4-------------------------*/

case 4:
while(1)
{
clrscr();
printf("\n    ============================Books Library==============================");
printf("         Date: %d/%d/%d",d.da_day,d.da_mon,d.da_year);
printf("\n\t\t\t    =====Remove Window=====");
printf("\n\n\tEnter Book id (Use first characters of words of book name): ");
fflush(stdin);
gets(b.book_id);
dat=fopen(b.book_id,"r");
if(dat==NULL)
{
printf("\n\tBook Does not Exist");
}
else
{
remove(b.book_id);
printf("\n\tBook Removed Successfully!");
}
printf("\n\n\tWant to Remove more books (Y/N): ");
scanf("%c",&yn);
if(yn=='N')
{
printf("\n\tPress any key to quit to main menu......");
getch();
break;
}
else if(yn=='n')
{
printf("\n\tPress any key to quit to main menu......");
getch();
break;
}
}
clrscr();
break;
/*--------------------End of Case 4----------------------*/

/*------------------------Case 5-------------------------*/

case 5: clrscr();
printf("\n    ============================Books Library==============================");
printf("         Date: %d/%d/%d",d.da_day,d.da_mon,d.da_year);
printf("\n\n    Thanks for using Software\n\n    A software by Sojitra Aadarsh");
printf("\n\n    Contact No.: 9662072282");
printf("\n\n    Location: Gujarat in India");
printf("\n\n    Program will terminate in 3 seconds");
delay(3000);
exit(0);

/*--------------------End of Case 5----------------------*/

/*---------------------Default Case----------------------*/

default:
printf("\n\n\tSYSTEM ERROR PLEASE RESTART SOFTWARE");
printf("\n\t\tProgram will terminate in 3 seconds");
delay(3000);
exit(0);

/*----------------------End of Default Case----------------------*/

}
}
getch();
}