#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
struct lib
{
int b_no;
char b_name[50];
char b_author[50];
char b_pub[50];
int no_of_cpy;
int b_rate;
int amt;
};
struct stud
{
char s_name[50];
char dept[50];
char s_class[8];
char issu_date[10];
int card_no;
char bookname[20];
};
typedef struct lib Book;
typedef struct stud Student;
Book a;
Student b;
void main()
{
FILE *fp,*fb;
char another,another1;
int c=0,i;
int choice;
fp=fopen("abc.txt","rb+");
fb=fopen("xyz.txt","rb+");
if(fp==NULL)
{
fp=fopen("abc.txt","wb+");
if(fp==NULL)
{
puts("cannot open file");
exit(1);
}
}
if(fb==NULL)
{
fb=fopen("xyz.txt","wb+");
if(fp==NULL)
{
puts("cannot open file");
exit(1);
}
}
while(c!=2)
{
clrscr();
printf("\n\n\n\n\t\t* * * * Library Managment System * * * *\n\n\n");
for(i=0;i<80;i++)
{
printf("*");
}
printf("\n\n\n\n\n\t\t1.\tAdd Liabrary Records");
printf("\n\n\n\n\n\t\t2.\tView Library Records");
printf("\n\n\n\n\n\t\t3.\tAdd Students Records");
printf("\n\n\n\n\n\t\t4.\tView Students Records");
printf("\n\n\n\n\n\t\t0.\tExit");
printf("\n\n\n\n\n\tEnter Your Choice=\t\t");
fflush(stdin);
scanf("%d",&choice);
switch(choice)
{
case 1:
fseek(fp,0,SEEK_END);
another='y';
while(another=='y')
{
clrscr();
printf("\n\n\n\tEnter the Number of Books\t\t");
scanf("%d",&a.b_no);
printf("\n\n\n\n\tEnter Name of Book\t\t\t");
fflush(stdin);
scanf("%s",a.b_name);
printf("\n\n\n\n\tEnter the Author's Name\t\t");
fflush(stdin);
scanf("%s",a.b_author);
printf("\n\n\n\n\tEnter Publication's Name\t");
fflush(stdin);
scanf("%s",a.b_pub);
printf("\n\n\n\n\tEnter the No_of_Cpys\t\t");
fflush(stdin);
scanf("%d",&a.no_of_cpy);
printf("\n\n\n\n\tEnter the Rate/cpy\t\t");
fflush(stdin);
scanf("%d",&a.b_rate);
a.amt=a.no_of_cpy*a.b_rate;
fwrite(&a,sizeof(a),1,fp);
printf("\n\n\n\n\t\tAdd Another Record(y/n)\t");
fflush(stdin);
scanf("%c",&another);
}
clrscr();
break;
case 2:
clrscr();
rewind(fp);
while(fread(&a,sizeof(a),1,fp))
{
clrscr();
printf("\n\n\n\n\tBook Number=\t\t\t%d",a.b_no);
printf("\n\n\n\n\tName of Book=\t\t\t%s",a.b_name);
printf("\n\n\n\n\tAuthor=\t\t\t\t%s",a.b_author);
printf("\n\n\n\n\tPublication=\t\t\t%s",a.b_pub);
printf("\n\n\n\n\tCopies of Books=\t\t%d",a.no_of_cpy);
printf("\n\n\n\n\tRate Per Book=\t\t\t%d",a.b_rate);
printf("\n\n\n\n\tTotal Amt of Books=\t\t%d",a.amt);
getch();
}
break;
case 3:
fseek(fb,0,SEEK_END);
another1='y';
while(another1=='y')
{
clrscr();
printf("\n\n\n\tEnter the Name of Student\t\t");
scanf("%s",b.s_name);
printf("\n\n\n\n\tEnter Name of Dept.\t\t\t");
fflush(stdin);
scanf("%s",b.dept);
printf("\n\n\n\n\tEnter the Class_name\t\t");
fflush(stdin);
scanf("%s",b.s_class);
printf("\n\n\n\n\tEnter Issue Date(dd/mm/yyyy)\t");
fflush(stdin);
scanf("%s",b.issu_date);
printf("\n\n\n\n\tEnter the Liabrary Card No\t\t");
fflush(stdin);
scanf("%d",&b.card_no);
printf("\n\n\n\n\tEnter the Book Name\t\t");
fflush(stdin);
scanf("%s",b.bookname);
fwrite(&b,sizeof(b),1,fb);
printf("\n\n\n\n\t\tAdd Another Record(y/n)\t");
fflush(stdin);
scanf("%c",&another1);
}
clrscr();
break;
case 4:
clrscr();
rewind(fb);
while(fread(&b,sizeof(b),1,fb))
{
clrscr();
printf("\n\n\n\n\tStudent Name=\t\t\t\t%s",b.s_name);
printf("\n\n\n\n\tDepartment=\t\t\t\t%s",b.dept);
printf("\n\n\n\n\tStudent's Class=\t\t\t%s",b.s_class);
printf("\n\n\n\n\tBook Issue Date=\t\t\t%s",b.issu_date);
printf("\n\n\n\n\tStudent's Liabrary Card_no=\t\t%d",b.card_no);
printf("\n\n\n\n\tBook's Name=\t\t\t\t%s",b.bookname);
getch();
}
break;
case 0: exit(0);
fcloseall();
}
}
getch();
}
#include<conio.h>
#include<stdlib.h>
#include<string.h>
struct lib
{
int b_no;
char b_name[50];
char b_author[50];
char b_pub[50];
int no_of_cpy;
int b_rate;
int amt;
};
struct stud
{
char s_name[50];
char dept[50];
char s_class[8];
char issu_date[10];
int card_no;
char bookname[20];
};
typedef struct lib Book;
typedef struct stud Student;
Book a;
Student b;
void main()
{
FILE *fp,*fb;
char another,another1;
int c=0,i;
int choice;
fp=fopen("abc.txt","rb+");
fb=fopen("xyz.txt","rb+");
if(fp==NULL)
{
fp=fopen("abc.txt","wb+");
if(fp==NULL)
{
puts("cannot open file");
exit(1);
}
}
if(fb==NULL)
{
fb=fopen("xyz.txt","wb+");
if(fp==NULL)
{
puts("cannot open file");
exit(1);
}
}
while(c!=2)
{
clrscr();
printf("\n\n\n\n\t\t* * * * Library Managment System * * * *\n\n\n");
for(i=0;i<80;i++)
{
printf("*");
}
printf("\n\n\n\n\n\t\t1.\tAdd Liabrary Records");
printf("\n\n\n\n\n\t\t2.\tView Library Records");
printf("\n\n\n\n\n\t\t3.\tAdd Students Records");
printf("\n\n\n\n\n\t\t4.\tView Students Records");
printf("\n\n\n\n\n\t\t0.\tExit");
printf("\n\n\n\n\n\tEnter Your Choice=\t\t");
fflush(stdin);
scanf("%d",&choice);
switch(choice)
{
case 1:
fseek(fp,0,SEEK_END);
another='y';
while(another=='y')
{
clrscr();
printf("\n\n\n\tEnter the Number of Books\t\t");
scanf("%d",&a.b_no);
printf("\n\n\n\n\tEnter Name of Book\t\t\t");
fflush(stdin);
scanf("%s",a.b_name);
printf("\n\n\n\n\tEnter the Author's Name\t\t");
fflush(stdin);
scanf("%s",a.b_author);
printf("\n\n\n\n\tEnter Publication's Name\t");
fflush(stdin);
scanf("%s",a.b_pub);
printf("\n\n\n\n\tEnter the No_of_Cpys\t\t");
fflush(stdin);
scanf("%d",&a.no_of_cpy);
printf("\n\n\n\n\tEnter the Rate/cpy\t\t");
fflush(stdin);
scanf("%d",&a.b_rate);
a.amt=a.no_of_cpy*a.b_rate;
fwrite(&a,sizeof(a),1,fp);
printf("\n\n\n\n\t\tAdd Another Record(y/n)\t");
fflush(stdin);
scanf("%c",&another);
}
clrscr();
break;
case 2:
clrscr();
rewind(fp);
while(fread(&a,sizeof(a),1,fp))
{
clrscr();
printf("\n\n\n\n\tBook Number=\t\t\t%d",a.b_no);
printf("\n\n\n\n\tName of Book=\t\t\t%s",a.b_name);
printf("\n\n\n\n\tAuthor=\t\t\t\t%s",a.b_author);
printf("\n\n\n\n\tPublication=\t\t\t%s",a.b_pub);
printf("\n\n\n\n\tCopies of Books=\t\t%d",a.no_of_cpy);
printf("\n\n\n\n\tRate Per Book=\t\t\t%d",a.b_rate);
printf("\n\n\n\n\tTotal Amt of Books=\t\t%d",a.amt);
getch();
}
break;
case 3:
fseek(fb,0,SEEK_END);
another1='y';
while(another1=='y')
{
clrscr();
printf("\n\n\n\tEnter the Name of Student\t\t");
scanf("%s",b.s_name);
printf("\n\n\n\n\tEnter Name of Dept.\t\t\t");
fflush(stdin);
scanf("%s",b.dept);
printf("\n\n\n\n\tEnter the Class_name\t\t");
fflush(stdin);
scanf("%s",b.s_class);
printf("\n\n\n\n\tEnter Issue Date(dd/mm/yyyy)\t");
fflush(stdin);
scanf("%s",b.issu_date);
printf("\n\n\n\n\tEnter the Liabrary Card No\t\t");
fflush(stdin);
scanf("%d",&b.card_no);
printf("\n\n\n\n\tEnter the Book Name\t\t");
fflush(stdin);
scanf("%s",b.bookname);
fwrite(&b,sizeof(b),1,fb);
printf("\n\n\n\n\t\tAdd Another Record(y/n)\t");
fflush(stdin);
scanf("%c",&another1);
}
clrscr();
break;
case 4:
clrscr();
rewind(fb);
while(fread(&b,sizeof(b),1,fb))
{
clrscr();
printf("\n\n\n\n\tStudent Name=\t\t\t\t%s",b.s_name);
printf("\n\n\n\n\tDepartment=\t\t\t\t%s",b.dept);
printf("\n\n\n\n\tStudent's Class=\t\t\t%s",b.s_class);
printf("\n\n\n\n\tBook Issue Date=\t\t\t%s",b.issu_date);
printf("\n\n\n\n\tStudent's Liabrary Card_no=\t\t%d",b.card_no);
printf("\n\n\n\n\tBook's Name=\t\t\t\t%s",b.bookname);
getch();
}
break;
case 0: exit(0);
fcloseall();
}
}
getch();
}