#include <stdio.h>
#include <stdlib.h>
typedef FILE* stream;
typedef char* string;
#define MAX_STUDENT 10
typedef struct
{
int id;
char name[30];
}stStud;
#define KEY 0xAB
const string menu[]={"Add new student", "print Student
information", "Quit"};
int displayMenu(void);
void fnEncryptDecrypt(unsigned char * inBuf, int numBytes,
unsigned char * outBuf);
void AddNewStud(stStud * studList, int * count);
void PrintStudentList(stStud * studList, int count);
void loadStudInfoFromFile(stStud * studList, int * count);
void WriteStudInfoToFile(stStud * studList, int count);
int main(void)
{
stStud studList[MAX_STUDENT];
int count = 0;
int sel;
loadStudInfoFromFile(studList, &count);
do
{
sel = displayMenu();
switch(sel)
{
case 1:
AddNewStud(studList, &count);
break;
case 2:
PrintStudentList(studList, count);
break;
case 3:
// quit
break;
default:
puts("Invalid Selection!!!");
}
}while(sel!=3);
WriteStudInfoToFile(studList, count);
return 0;
}
int displayMenu(void)
{
int i;
int sel;
puts("ttStudent Menu");
for(i=0 ; i<sizeof(menu)/sizeof(menu[0]) ; ++i)
{
printf("%i. %sn", i+1, menu[i]);
}
printf("Select: ");
scanf("%i", &sel);
return sel;
}
//add students to the array
void AddNewStud(stStud * studList, int * count)
{
printf("Enter Student ID:");
scanf("%i", &studList[*count].id);
printf("Enter Student name:");
scanf(" %39[^n]", studList[*count].name);
(*count)++;
}
void PrintStudentList(stStud * studList, int count)
{
int i;
for(i=0;i<count;++i)
{
printf("Stud ID: %i, t Student Name: %sn",
studList[i].id, studList[i].name);
}
}
void loadStudInfoFromFile(stStud * studList, int * count)
{
int ret;
stream in;
unsigned char* buf;
in = fopen("stud.bin", "rb");
if(in != NULL)
{
buf = (unsigned char *)malloc (sizeof(int));
ret = fread(buf,sizeof(int),1,in);
if(ret == 1)
{
fnEncryptDecrypt(buf, sizeof(int), (unsigned
char *) count);
free(buf);
buf = (unsigned char *) malloc ((*count) *
sizeof(stStud));
fread(buf,(*count) * sizeof(stStud),1,in);
fnEncryptDecrypt(buf , (*count) *
sizeof(stStud), (unsigned char *) studList);
}
free(buf);
fclose(in);
}
}
void WriteStudInfoToFile(stStud * studList, int count)
{
stream out;
unsigned char * buf;
buf = malloc (sizeof(int));
fnEncryptDecrypt((unsigned char *) &count, sizeof(int),
buf);
out = fopen("stud.bin", "wb");
fwrite(buf,sizeof(int),1,out);
free(buf);
buf =(unsigned char*) malloc (count * sizeof(stStud));
fnEncryptDecrypt((unsigned char *) studList, count *
sizeof(stStud), buf);
fwrite(buf,count * sizeof(stStud),1,out);
free(buf);
fclose(out);
}
void fnEncryptDecrypt(unsigned char * inBuf, int numBytes,
unsigned char * outBuf)
{
int i;
for(i=0; i< numBytes;++i)
{
outBuf[i] = inBuf[i] ^ KEY;
}
}
/****************************Group No.07
Assignment****************************
***************************Group Members:
1.Danda, Praveen
2.Rachamalla, Sandeep
3.Ghaida Almugrin
4.Alghamdi, Hoosam G.
*****************************************************
**************************/
#include<stdio.h>
/**********************STUDENT
functions*****************/
void enterStudentDetails();
void printAllstudentsDetails();
int findStudentByRoleNumber(int);
void findStudentByName();
int searchGmail(char[]);
/************************ BOOK *****************/
void addBook();
void printAllBooksList();
int findBookById(int);
void findBookById1();
void findBookByISBN();
void findBookByName();
/********************** Enter Studente Details
******************************/
void enterStudentDetails()
{
int roll,ch,res;
char name[50],email[50];
int flag=0,flag1=0;
FILE *fp;
clrscr();
fp = fopen("student.txt","a");
printf("n ENTER ROLL NUMBER : ");
scanf("%d",&roll);
flag=findStudentByRoleNumber(roll);
if(flag!=1)
{
printf("ENTER NAME :n");
scanf("%s",&name);
printf("ENTER EMAIL:n");
scanf("%s",&email);
flag1=searchGmail(email);
if(flag1!=1)
{
fprintf(fp,"%d %s %sn",roll,name,email);
}
else
{
printf("n email already registered, take a new
Emailn");
}
}
else
{
printf("This Student Number already registered .If u
want add new student take another New RoleNumber :n");
}
fclose(fp) ;
}
/******************* Search gmail
************************/
int searchGmail(char semail[50])
{
int i,ch,roll;
char email[50],name[50];
FILE *fm;
fm = fopen("student.txt","r");
i=0;
while(! feof(fm))
{
fscanf(fm,"%d%s%sn",&roll,&name,&email);
if(strcmp(email,semail)==0)
{
i=1;
printf("nROLLNO. NAME GMAILn ");
printf(" %d %s %s",roll,name,email);
break;
}
}
fclose(fm);
return i;
}
/********************Print All Students
Details**************/
void printAllstudentsDetails()
{
int rollno[100],x[100],i;
char name[100][50],email[100][50];
FILE *fp;
clrscr();
fp = fopen("student.txt","r");
i=0;
printf("ROLLNO NAME EMAILn");
while(!feof(fp))
{
fscanf(fp,"%d %s %sn",&rollno[i],&name[i],&email[i]);
printf(" %d %s
%sn",rollno[i],name[i],email[i]);
i=i+1;
}
fclose(fp);
printf("nnnPRESS ANY KEY");
getch();
}
/************************* Print Student Details using
RoleNumber ***************************/
int findStudentByRoleNumber(int roll1)
{
int i,ch,roll,mark,sroll;
char name[50],email[50];
FILE *fm;
fm = fopen("student.txt","r");
i=0;
while(! feof(fm))
{
fscanf(fm,"%d%s%sn",&roll,&name,&email);
if(roll1==roll)
{
printf("nROLLNO. NAME GMAILn ");
printf(" %d %s %sn",roll,name,email);
i=1;
break;
}//endif
}
if(i==0)
{
printf("n%d",roll1);
printf(" Rolenumber does not exit in the recordn");
}
fclose(fm);
return i;
}
/************************* To find Student information
using student name***************************/
void findStudentByName()
{
int i=0,roll,ch,mark,roll1;
char name[50],email[50],sname[50];
FILE *fm;
ch=1;
while(ch)
{
fm = fopen("student.txt","r");
printf(" n ENTER STUDENT NAME ");
scanf("%s",&sname);
while(! feof(fm))
{
fscanf(fm,"%d%s%sn",&roll,&name,&email);
if(strcmp(sname,name)==0)
{
i=1;
printf("nROLLNO. NAME GMAILn ");
printf(" %d %s %s",roll,name,email);
break;
}
}
// printf("------i----->%d",i);
if(i==0)
{
printf("n%s",sname);
printf(" name does not exit in the record");
}
printf("nnpress 1 to see Another Student info, otherwise
Press 0 to return to main menu: n");
scanf("%d",&ch);
fclose(fm);
}
}
/************** BOOKS FUNCTIONS
*******************/
void addBook()
{
int
i,ch,res,sbookid,bookid,quantity,bookISBN,booksIdPresentEnter
[50];
char bookName[50],author[50];
FILE *fp;
clrscr();
fp = fopen("book.txt","a");
ch =1;
while(ch)
{
printf("Enter no of books:");
scanf("%d",&quantity);
printf("Enter book isbn :");
scanf("%d",&bookISBN);
printf("Enter BookNAME :");
scanf("%s",&bookName);
printf("Enter Author :");
scanf("%s",&author);
for(i=quantity;i>=1;i--)
{
fp = fopen("book.txt","a");
res=0;
printf("nEnter book Id : ");
scanf("%d",&sbookid);
res=findBookById(sbookid);
if(res!=1)
{
fprintf(fp,"%d %s %s %d %d
n",sbookid,bookName,author,quantity,bookISBN);
booksIdPresentEnter[i]=sbookid;
fclose(fp);
}
else
{
printf("nBookID what ever you enterd already
registered ,Take a new BookID ");
i++;
}
}
printf("n n press 1 to continue,0 to stop : ");
scanf("%d",&ch);
}
fclose(fp) ;
}
/* --------------- PRINT ALL BOOKS-------------------------*/
void printAllBooksList()
{
int bookId[50],quantity[50],bookISBN[50],i;
char bookName[100][50],author[50][100],ch;
FILE *fp;
clrscr();
fp = fopen("book.txt","r");
i=0;
printf("BookNumber BookNAME Author NoOfBooks
ISBNn");
while(! feof(fp))
{
fscanf(fp,"%d%s%s%d%dn",&bookId[i],&bookName[i],&autho
r[i],&quantity[i],&bookISBN[i]);
printf("%d %s %s %d
%dn",bookId[i],bookName[i],author[i],quantity[i],bookISBN[i]
);
i=i+1;
}
fclose(fp);
printf("nnnPRESS ANY KEY");
getch();
}
/* ---------------------- find book by ID --------------------*/
void findBookById1()
{
int i,ch,bid,isbn,quantity,sbid;
char bname[50],author[50];
FILE *fm;
ch=1;
while(ch)
{
fm = fopen("book.txt","r");
printf(" n ENTER BOOK ID :");
scanf("%d",&sbid);
i=0;
while(! feof(fm))
{
//printf("------- find book by ID while 1-----n");
fscanf(fm,"%d%s%s%d%dn",&bid,&bname,&author,&quantity,
&isbn);
if(sbid==bid)
{
printf("n bookID BookName Author quantity
ISBNnumbern ");
printf(" %d %s %s %d
%dn",bid,bname,author,quantity,isbn);
break;
}
else
i=i+1;
}
printf("nnpress 1 to see another book info, 0 to return to
main menun");
scanf("%d",&ch);
fclose(fm);
}
}
/*-------int findBookById(int sbid)------*/
int findBookById(int sbid)
{
int i=0,ch,bid,isbn,quantity;
char bname[50],author[50];
FILE *fm;
fm = fopen("book.txt","r");
while(! feof(fm))
{
fscanf(fm,"%d%s%s%d%dn",&bid,&bname,&author,&quantity,
&isbn);
if(sbid==bid)
{
printf("n bookID BookName Author quantity
ISBNnumbern");
printf(" %d %s %s %d
%dn",bid,bname,author,quantity,isbn);
i=1;
break;
}
}
fclose(fm);
return i;
}
/*--------------------------- findBookByISBN-----------------*/
void findBookByISBN()
{
int i,ch,bid,isbn,quantity,sisbn;
char bname[50],author[50];
FILE *fm;
ch=1;
while(ch)
{
fm = fopen("book.txt","r");
printf(" n ENTER BOOK ISBN :");
scanf("%d",&sisbn);
i=0;
while(! feof(fm))
{
fscanf(fm,"%d%s%s%d%dn",&bid,&bname,&author,&quantity,
&isbn);
if(isbn==sisbn)
{
printf("n bookID BookName Author quantity
ISBNnumbern ");
printf(" %d %s %s %d
%dn",bid,bname,author,quantity,isbn);
break;
}
else
i=i+1;
}
printf("nnpress 1 to see another book info, 0 to return to
main menu :");
scanf("%d",&ch);
fclose(fm);
}
}
/*--------------------------- find Book By its name-----------------
*/
void findBookByName()
{
int ch,bid,isbn,quantity;
char bname[50],author[50],sbname[50];
FILE *fm;
ch=1;
while(ch)
{
fm = fopen("book.txt","r");
printf(" n ENTER BOOK NAME :");
scanf("%s",&sbname);
while(!feof(fm))
{
fscanf(fm,"%d %s %s %d
%sn",&bid,&bname,&author,&quantity,&isbn);
if(strcmp(sbname,bname) == 0)
{
printf("n bookID BookName Author quantity
ISBNnumbern ");
printf(" %d %s %s %d
%dn",bid,bname,author,quantity,isbn);
break;
}
}
printf("nnpress 1 to see another Book info, 0 to return to
main menu :");
scanf("%d",&ch);
fclose(fm);
}
}
/**************** FUNC.
ENDS************************/
void main()
{
int i,rollno[100],x[100],n,j,roll,c,roll1,sroll,res,sbid;
char ch,name[100][10],email;
while(c!=10)
{
printf("GIVE CHOICE--n");
printf(" 1 TO ENTER STUDENT INFORMATIONn");
printf(" 2 TO SEE ALL STUDENTS INFORMATIONn");
printf(" 3 TO PRINT STUDENT INFOORMATION USING
ROLL NOn");
printf(" 4 TO PRINT STUDENT INFO. USING HIS
NAMEn");
printf(" 5 TO ENTER New Book INFO.n");
printf(" 6 TO PRINT ALL BOOKS INFO.n");
printf(" 7 TO Find BOOK INFO by BookById.n");
printf(" 8 TO Find Book Info By ISBN number.n");
printf(" 9 TO Find Book Info By its Name.n");
printf(" 10 QUIT nn--");
scanf("%d",&c);
clrscr();
switch(c)
{
case 1:
enterStudentDetails();
break;
case 2:
printAllstudentsDetails();
break;
case 3:
do
{
res=0;
printf("Enter Student Roll Number-----> ");
scanf("%d",&roll1);
res=findStudentByRoleNumber(roll1);
printf("nDo u want search again if yes
PRESS 1 else PRESS 0 :");
scanf("%d",&i);
}while(i!=0);
if(res==0)
{
printf("nThis RoleNumberis not yet
registered");
}
break;
case 4:
findStudentByName();
break;
case 5:
addBook();
break;
case 6:
printAllBooksList();
break;
case 7:
findBookById1();
break;
case 8:
findBookByISBN();
break;
case 9:
findBookByName();
break;
case 10:
exit();
break;
default:
break;
}
}
}
S14_CSCI 6610
Assignment 3
Enhance your library system with the following set of
requirements:
1) Use dynamic memory allocation for the book array and
student array. This will help your program to expand without
any limitation on fixed number of books or students.
2) Use binary files to store the data instead of using text files.
You’ll be using binary modes instead of a text mode.
3) Data has to be encrypted before it gets stored in file. Use 8
bits key encryption using “exclusive or” operator (^) as we
discussed in the class. Data has to be decrypted before loading
the arrays again.

#include stdio.h#include stdlib.htypedef FILE stream.docx

  • 1.
    #include <stdio.h> #include <stdlib.h> typedefFILE* stream; typedef char* string; #define MAX_STUDENT 10 typedef struct { int id; char name[30]; }stStud; #define KEY 0xAB const string menu[]={"Add new student", "print Student information", "Quit"};
  • 2.
    int displayMenu(void); void fnEncryptDecrypt(unsignedchar * inBuf, int numBytes, unsigned char * outBuf); void AddNewStud(stStud * studList, int * count); void PrintStudentList(stStud * studList, int count); void loadStudInfoFromFile(stStud * studList, int * count); void WriteStudInfoToFile(stStud * studList, int count); int main(void) { stStud studList[MAX_STUDENT]; int count = 0; int sel; loadStudInfoFromFile(studList, &count); do {
  • 3.
    sel = displayMenu(); switch(sel) { case1: AddNewStud(studList, &count); break; case 2: PrintStudentList(studList, count); break; case 3: // quit break; default: puts("Invalid Selection!!!"); } }while(sel!=3); WriteStudInfoToFile(studList, count);
  • 4.
    return 0; } int displayMenu(void) { inti; int sel; puts("ttStudent Menu"); for(i=0 ; i<sizeof(menu)/sizeof(menu[0]) ; ++i) { printf("%i. %sn", i+1, menu[i]); } printf("Select: "); scanf("%i", &sel); return sel;
  • 5.
    } //add students tothe array void AddNewStud(stStud * studList, int * count) { printf("Enter Student ID:"); scanf("%i", &studList[*count].id); printf("Enter Student name:"); scanf(" %39[^n]", studList[*count].name); (*count)++; } void PrintStudentList(stStud * studList, int count) { int i; for(i=0;i<count;++i) { printf("Stud ID: %i, t Student Name: %sn", studList[i].id, studList[i].name);
  • 6.
    } } void loadStudInfoFromFile(stStud *studList, int * count) { int ret; stream in; unsigned char* buf; in = fopen("stud.bin", "rb"); if(in != NULL) { buf = (unsigned char *)malloc (sizeof(int)); ret = fread(buf,sizeof(int),1,in); if(ret == 1) { fnEncryptDecrypt(buf, sizeof(int), (unsigned
  • 7.
    char *) count); free(buf); buf= (unsigned char *) malloc ((*count) * sizeof(stStud)); fread(buf,(*count) * sizeof(stStud),1,in); fnEncryptDecrypt(buf , (*count) * sizeof(stStud), (unsigned char *) studList); } free(buf); fclose(in); } } void WriteStudInfoToFile(stStud * studList, int count) { stream out; unsigned char * buf; buf = malloc (sizeof(int)); fnEncryptDecrypt((unsigned char *) &count, sizeof(int), buf);
  • 8.
    out = fopen("stud.bin","wb"); fwrite(buf,sizeof(int),1,out); free(buf); buf =(unsigned char*) malloc (count * sizeof(stStud)); fnEncryptDecrypt((unsigned char *) studList, count * sizeof(stStud), buf); fwrite(buf,count * sizeof(stStud),1,out); free(buf); fclose(out); } void fnEncryptDecrypt(unsigned char * inBuf, int numBytes, unsigned char * outBuf) { int i; for(i=0; i< numBytes;++i) {
  • 9.
    outBuf[i] = inBuf[i]^ KEY; } } /****************************Group No.07 Assignment**************************** ***************************Group Members: 1.Danda, Praveen 2.Rachamalla, Sandeep 3.Ghaida Almugrin 4.Alghamdi, Hoosam G. ***************************************************** **************************/ #include<stdio.h> /**********************STUDENT functions*****************/ void enterStudentDetails(); void printAllstudentsDetails(); int findStudentByRoleNumber(int);
  • 10.
    void findStudentByName(); int searchGmail(char[]); /************************BOOK *****************/ void addBook(); void printAllBooksList(); int findBookById(int); void findBookById1(); void findBookByISBN(); void findBookByName(); /********************** Enter Studente Details ******************************/ void enterStudentDetails() { int roll,ch,res; char name[50],email[50]; int flag=0,flag1=0;
  • 11.
    FILE *fp; clrscr(); fp =fopen("student.txt","a"); printf("n ENTER ROLL NUMBER : "); scanf("%d",&roll); flag=findStudentByRoleNumber(roll); if(flag!=1) { printf("ENTER NAME :n"); scanf("%s",&name); printf("ENTER EMAIL:n"); scanf("%s",&email); flag1=searchGmail(email); if(flag1!=1) {
  • 12.
    fprintf(fp,"%d %s %sn",roll,name,email); } else { printf("nemail already registered, take a new Emailn"); } } else { printf("This Student Number already registered .If u want add new student take another New RoleNumber :n"); } fclose(fp) ; } /******************* Search gmail ************************/
  • 13.
    int searchGmail(char semail[50]) { inti,ch,roll; char email[50],name[50]; FILE *fm; fm = fopen("student.txt","r"); i=0; while(! feof(fm)) { fscanf(fm,"%d%s%sn",&roll,&name,&email); if(strcmp(email,semail)==0) { i=1; printf("nROLLNO. NAME GMAILn "); printf(" %d %s %s",roll,name,email); break; }
  • 14.
    } fclose(fm); return i; } /********************Print AllStudents Details**************/ void printAllstudentsDetails() { int rollno[100],x[100],i; char name[100][50],email[100][50]; FILE *fp; clrscr(); fp = fopen("student.txt","r"); i=0; printf("ROLLNO NAME EMAILn"); while(!feof(fp))
  • 15.
    { fscanf(fp,"%d %s %sn",&rollno[i],&name[i],&email[i]); printf("%d %s %sn",rollno[i],name[i],email[i]); i=i+1; } fclose(fp); printf("nnnPRESS ANY KEY"); getch(); } /************************* Print Student Details using RoleNumber ***************************/ int findStudentByRoleNumber(int roll1) { int i,ch,roll,mark,sroll; char name[50],email[50];
  • 16.
    FILE *fm; fm =fopen("student.txt","r"); i=0; while(! feof(fm)) { fscanf(fm,"%d%s%sn",&roll,&name,&email); if(roll1==roll) { printf("nROLLNO. NAME GMAILn "); printf(" %d %s %sn",roll,name,email); i=1; break; }//endif } if(i==0)
  • 17.
    { printf("n%d",roll1); printf(" Rolenumber doesnot exit in the recordn"); } fclose(fm); return i; } /************************* To find Student information using student name***************************/ void findStudentByName() { int i=0,roll,ch,mark,roll1; char name[50],email[50],sname[50]; FILE *fm; ch=1;
  • 18.
    while(ch) { fm = fopen("student.txt","r"); printf("n ENTER STUDENT NAME "); scanf("%s",&sname); while(! feof(fm)) { fscanf(fm,"%d%s%sn",&roll,&name,&email); if(strcmp(sname,name)==0) { i=1; printf("nROLLNO. NAME GMAILn "); printf(" %d %s %s",roll,name,email); break; } }
  • 19.
    // printf("------i----->%d",i); if(i==0) { printf("n%s",sname); printf(" namedoes not exit in the record"); } printf("nnpress 1 to see Another Student info, otherwise Press 0 to return to main menu: n"); scanf("%d",&ch); fclose(fm); } } /************** BOOKS FUNCTIONS *******************/ void addBook() {
  • 20.
    int i,ch,res,sbookid,bookid,quantity,bookISBN,booksIdPresentEnter [50]; char bookName[50],author[50]; FILE *fp; clrscr(); fp= fopen("book.txt","a"); ch =1; while(ch) { printf("Enter no of books:"); scanf("%d",&quantity); printf("Enter book isbn :"); scanf("%d",&bookISBN); printf("Enter BookNAME :"); scanf("%s",&bookName); printf("Enter Author :"); scanf("%s",&author);
  • 21.
    for(i=quantity;i>=1;i--) { fp = fopen("book.txt","a"); res=0; printf("nEnterbook Id : "); scanf("%d",&sbookid); res=findBookById(sbookid); if(res!=1) { fprintf(fp,"%d %s %s %d %d n",sbookid,bookName,author,quantity,bookISBN); booksIdPresentEnter[i]=sbookid; fclose(fp); } else { printf("nBookID what ever you enterd already registered ,Take a new BookID ");
  • 22.
    i++; } } printf("n n press1 to continue,0 to stop : "); scanf("%d",&ch); } fclose(fp) ; } /* --------------- PRINT ALL BOOKS-------------------------*/ void printAllBooksList() { int bookId[50],quantity[50],bookISBN[50],i; char bookName[100][50],author[50][100],ch; FILE *fp;
  • 23.
    clrscr(); fp = fopen("book.txt","r"); i=0; printf("BookNumberBookNAME Author NoOfBooks ISBNn"); while(! feof(fp)) { fscanf(fp,"%d%s%s%d%dn",&bookId[i],&bookName[i],&autho r[i],&quantity[i],&bookISBN[i]); printf("%d %s %s %d %dn",bookId[i],bookName[i],author[i],quantity[i],bookISBN[i] ); i=i+1; } fclose(fp); printf("nnnPRESS ANY KEY"); getch(); }
  • 24.
    /* ---------------------- findbook by ID --------------------*/ void findBookById1() { int i,ch,bid,isbn,quantity,sbid; char bname[50],author[50]; FILE *fm; ch=1; while(ch) { fm = fopen("book.txt","r"); printf(" n ENTER BOOK ID :"); scanf("%d",&sbid); i=0; while(! feof(fm)) {
  • 25.
    //printf("------- find bookby ID while 1-----n"); fscanf(fm,"%d%s%s%d%dn",&bid,&bname,&author,&quantity, &isbn); if(sbid==bid) { printf("n bookID BookName Author quantity ISBNnumbern "); printf(" %d %s %s %d %dn",bid,bname,author,quantity,isbn); break; } else i=i+1; } printf("nnpress 1 to see another book info, 0 to return to main menun"); scanf("%d",&ch); fclose(fm); }
  • 26.
    } /*-------int findBookById(int sbid)------*/ intfindBookById(int sbid) { int i=0,ch,bid,isbn,quantity; char bname[50],author[50]; FILE *fm; fm = fopen("book.txt","r"); while(! feof(fm)) { fscanf(fm,"%d%s%s%d%dn",&bid,&bname,&author,&quantity, &isbn); if(sbid==bid) { printf("n bookID BookName Author quantity ISBNnumbern");
  • 27.
    printf(" %d %s%s %d %dn",bid,bname,author,quantity,isbn); i=1; break; } } fclose(fm); return i; } /*--------------------------- findBookByISBN-----------------*/ void findBookByISBN() { int i,ch,bid,isbn,quantity,sisbn; char bname[50],author[50]; FILE *fm; ch=1;
  • 28.
    while(ch) { fm = fopen("book.txt","r"); printf("n ENTER BOOK ISBN :"); scanf("%d",&sisbn); i=0; while(! feof(fm)) { fscanf(fm,"%d%s%s%d%dn",&bid,&bname,&author,&quantity, &isbn); if(isbn==sisbn) { printf("n bookID BookName Author quantity ISBNnumbern "); printf(" %d %s %s %d %dn",bid,bname,author,quantity,isbn); break; } else
  • 29.
    i=i+1; } printf("nnpress 1 tosee another book info, 0 to return to main menu :"); scanf("%d",&ch); fclose(fm); } } /*--------------------------- find Book By its name----------------- */ void findBookByName() { int ch,bid,isbn,quantity; char bname[50],author[50],sbname[50]; FILE *fm; ch=1; while(ch)
  • 30.
    { fm = fopen("book.txt","r"); printf("n ENTER BOOK NAME :"); scanf("%s",&sbname); while(!feof(fm)) { fscanf(fm,"%d %s %s %d %sn",&bid,&bname,&author,&quantity,&isbn); if(strcmp(sbname,bname) == 0) { printf("n bookID BookName Author quantity ISBNnumbern "); printf(" %d %s %s %d %dn",bid,bname,author,quantity,isbn); break; } } printf("nnpress 1 to see another Book info, 0 to return to
  • 31.
    main menu :"); scanf("%d",&ch); fclose(fm); } } /****************FUNC. ENDS************************/ void main() { int i,rollno[100],x[100],n,j,roll,c,roll1,sroll,res,sbid; char ch,name[100][10],email; while(c!=10) { printf("GIVE CHOICE--n"); printf(" 1 TO ENTER STUDENT INFORMATIONn"); printf(" 2 TO SEE ALL STUDENTS INFORMATIONn");
  • 32.
    printf(" 3 TOPRINT STUDENT INFOORMATION USING ROLL NOn"); printf(" 4 TO PRINT STUDENT INFO. USING HIS NAMEn"); printf(" 5 TO ENTER New Book INFO.n"); printf(" 6 TO PRINT ALL BOOKS INFO.n"); printf(" 7 TO Find BOOK INFO by BookById.n"); printf(" 8 TO Find Book Info By ISBN number.n"); printf(" 9 TO Find Book Info By its Name.n"); printf(" 10 QUIT nn--"); scanf("%d",&c); clrscr(); switch(c) { case 1: enterStudentDetails(); break; case 2:
  • 33.
    printAllstudentsDetails(); break; case 3: do { res=0; printf("Enter StudentRoll Number-----> "); scanf("%d",&roll1); res=findStudentByRoleNumber(roll1); printf("nDo u want search again if yes PRESS 1 else PRESS 0 :"); scanf("%d",&i); }while(i!=0); if(res==0) { printf("nThis RoleNumberis not yet registered");
  • 34.
    } break; case 4: findStudentByName(); break; case 5: addBook(); break; case6: printAllBooksList(); break; case 7: findBookById1();
  • 35.
  • 36.
    } S14_CSCI 6610 Assignment 3 Enhanceyour library system with the following set of requirements: 1) Use dynamic memory allocation for the book array and student array. This will help your program to expand without any limitation on fixed number of books or students. 2) Use binary files to store the data instead of using text files. You’ll be using binary modes instead of a text mode. 3) Data has to be encrypted before it gets stored in file. Use 8 bits key encryption using “exclusive or” operator (^) as we discussed in the class. Data has to be decrypted before loading the arrays again.