Вы находитесь на странице: 1из 5

//list of header files

#include "general_functions.h"
#include "core_functions.h"
char ch;
int choice,i;
int main(){
mainmenu();
return 0;
}
void mainmenu()
{
while(1){
printf("\n********** MAIN MENU ***********\n");
printf("1. Add student record\n");
printf("2. Delete student record\n");
printf("3. Search student record\n");
printf("4. View student List\n");
printf("5. Edit student Record \n");
printf("6. Sorting record branch-wise");
printf("7. Exit\n");
printf("\nEnter your choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1:
addStudentRecord() ;
break;
case 2:
deleteStudentRecord( );
break;
case 3:
searchStudentRecord();
break;
case 4:
displayStudentRecords() ;
break;
case 5:
modifyStudentRecord( );
break;
case 6:
branchWiseSorting();
break;
case 7:
exit(0);
break;
default:
printf("\aWrong Entry!!Please re-entered correct option");
}

}
}
void deleteStudentRecord(void){

//funtion that add books

FILE *fp;
int i, choice;
add_window();
printf("Enter your choice:");
scanf("%d", &choice);
if(choice==7)
mainmenu();
fp = fopen("Record.dat","ab+");
if(getdata(choice) == 1){
book.cat=catagories[choice-1];
fseek(fp,0,SEEK_END);
fwrite(&book,sizeof(book),1,fp);
fclose(fp);
printf("\nThe record is sucessfully saved\n");
printf("Save any more?(Y / N):");
scanf(" %c",&ch);
if(ch=='n' || ch=='N')
mainmenu();
else{
addbooks();
}
}
fclose(fp);
}
void deleteStudentRecord(){
//function that delete items from file Record.dat
FILE *ft,*fp;
int d,findBook = 0;
char another='y';
while(another=='y'){ //infinite loop
printf("Enter the Book ID to delete:");
scanf("%d",&d);
fp = fopen("Record.dat","rb+");
while(fread(&book,sizeof(book),1,fp)==1){
if(book.id==d){
printf("\nThe book record is available\n");
printf("Book name is %s\n",book.title);
printf("Edition is %d\n",book.edition);
findBook = 1;
ft=fopen("test.dat","wb"); //temporary file for delete
rewind(fp);
while(fread(&book,sizeof(book),1,fp)==1){
if(book.id!=d){
fwrite(&book,sizeof(book),1,ft);
}
}
fclose(ft);
fclose(fp);
remove("Record.dat");
rename("test.dat","Record.dat");

printf("The record is sucessfully deleted\n");


}
}
if(findBook == 0){
printf("No record is found\n");
}
printf("Delete another record?(Y/N)\n");
scanf(" %c",&ch);
if(ch!='y'||ch!='Y')
{
another='n';
}
}
}

void searchStudentRecord()
{
printf("\n*********************Search Books**************************\n");
printf("\n1. Search By ID\n");
printf("\n2. Search By Name\n");
printf("Enter Your Choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
searchByID();
break;
case 2:
searchByName();
break;
default :
searchbooks();
}
}
void displayStudentRecords(void) //show the list of book persists in library
{
int j;
FILE *fp;
printf("*********************************Book List**************************
*\n");
printf("Department ID BOOKTITLE PUB. TYPE
O-P\n");
j=4;
fp=fopen("Record.dat","rb");
while(fread(&book,sizeof(book),1,fp)==1){
printf("%s ",book.cat);
printf("%d ",book.id);

AUTHOR

Edition

PRICE D-

printf("%s\t ",book.title);
printf("%s ",book.pub);
printf("%s ",book.type);
printf("%s ",book.Author);
printf("%d ",book.edition);
printf("%.2f\t",book.Price);
printf("%d",book.dop);
printf("\n\n");
j++;
}
fclose(fp);
returnfunc();
}
void modifyStudentRecord(void) //edit information about book
{
FILE *fp;
int c=0,d;
printf("\n****Edit Books Section****\n");
char another='y';
while(another=='y')
{
printf("Enter Book Id to be edited: ");
scanf("%d",&d);
fp=fopen("Record.dat","rb+");
while(fread(&book,sizeof(book),1,fp)==1)
{
if(checkid(d)==0)
{
printf("The book is availble\n");
printf("The Book ID:%d\n",book.id);
printf("Enter new title:\n");
scanf("%s",book.title);
printf("Enter new Publication\n");
scanf("%s",book.pub);
printf("Enter new type\n");
scanf("%s",book.type);
printf("Enter new Author:\n");
scanf("%s",book.Author);
printf("Enter new Edition:\n");
scanf("%d",&book.edition);
printf("Enter new price:\n");
scanf("%f",&book.Price);
printf("Enter new Date of Purchase:\n");
scanf("%d",&book.dop);
printf("The record is modified\n");
fseek(fp,ftell(fp)-sizeof(book),0);
fwrite(&book,sizeof(book),1,fp);
fclose(fp);

c=1;
}
if(c==0)
{
printf("No record found\n");
}
}
printf("\nModify another Record?(Y/N)\n");
scanf(" %c",&ch);
if(ch!='y' || ch!='Y')
{
another='n';
}
}
returnfunc();
}