SlideShare a Scribd company logo
#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.

More Related Content

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

c programming
c programmingc programming
c programming
Arun Umrao
 
C program
C programC program
C program
Komal Singh
 
Presentation for structure in c
Presentation for  structure in cPresentation for  structure in c
Presentation for structure in c
MdSaydurRahmanRifat
 
(C++ programming)menu quit, book show, book change, book remo.docx
(C++ programming)menu  quit, book show, book change, book remo.docx(C++ programming)menu  quit, book show, book change, book remo.docx
(C++ programming)menu quit, book show, book change, book remo.docx
ajoy21
 
#include stdio.hint main() {     int count;     FILE myFi.pdf
#include stdio.hint main() {     int count;     FILE myFi.pdf#include stdio.hint main() {     int count;     FILE myFi.pdf
#include stdio.hint main() {     int count;     FILE myFi.pdf
anithareadymade
 
struct procedure {    Date dateOfProcedure;    int procedureID.pdf
struct procedure {    Date dateOfProcedure;    int procedureID.pdfstruct procedure {    Date dateOfProcedure;    int procedureID.pdf
struct procedure {    Date dateOfProcedure;    int procedureID.pdf
anonaeon
 
DSA.pdf
DSA.pdfDSA.pdf
DSA.pdf
Rishab Saini
 
9.C Programming
9.C Programming9.C Programming
9.C Programming
Export Promotion Bureau
 
(Meta 5) ejemplo vectores dev c++
(Meta 5) ejemplo vectores dev c++ (Meta 5) ejemplo vectores dev c++
(Meta 5) ejemplo vectores dev c++
Eli Diaz
 
(Meta 5) ejemplo vectores 2 dev c++
(Meta 5) ejemplo vectores 2 dev c++ (Meta 5) ejemplo vectores 2 dev c++
(Meta 5) ejemplo vectores 2 dev c++
Eli Diaz
 
#include stdafx.h#include iostream#include Stringusing.pdf
#include stdafx.h#include iostream#include Stringusing.pdf#include stdafx.h#include iostream#include Stringusing.pdf
#include stdafx.h#include iostream#include Stringusing.pdf
anokhilalmobile
 
sodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdfsodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdf
MuhammadMaazShaik
 
Complete DB code following the instructions Implement the D.pdf
Complete DB code following the instructions Implement the D.pdfComplete DB code following the instructions Implement the D.pdf
Complete DB code following the instructions Implement the D.pdf
access2future1
 
__MACOSX._assign3assign3.DS_Store__MACOSXassign3._.D.docx
__MACOSX._assign3assign3.DS_Store__MACOSXassign3._.D.docx__MACOSX._assign3assign3.DS_Store__MACOSXassign3._.D.docx
__MACOSX._assign3assign3.DS_Store__MACOSXassign3._.D.docx
odiliagilby
 
#include iostream #include fstream #include map #include.pdf
#include iostream #include fstream #include map #include.pdf#include iostream #include fstream #include map #include.pdf
#include iostream #include fstream #include map #include.pdf
inbox5
 
program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)
Ankit Gupta
 
I have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdfI have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdf
ezzi552
 
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docxcmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
gordienaysmythe
 
selection_sort..c#include stdio.hheader file input output func.pdf
selection_sort..c#include stdio.hheader file input output func.pdfselection_sort..c#include stdio.hheader file input output func.pdf
selection_sort..c#include stdio.hheader file input output func.pdf
anton291
 
Data structures
Data structuresData structures
Data structures
gayatrigayu1
 

Similar to #include stdio.h#include stdlib.htypedef FILE stream.docx (20)

c programming
c programmingc programming
c programming
 
C program
C programC program
C program
 
Presentation for structure in c
Presentation for  structure in cPresentation for  structure in c
Presentation for structure in c
 
(C++ programming)menu quit, book show, book change, book remo.docx
(C++ programming)menu  quit, book show, book change, book remo.docx(C++ programming)menu  quit, book show, book change, book remo.docx
(C++ programming)menu quit, book show, book change, book remo.docx
 
#include stdio.hint main() {     int count;     FILE myFi.pdf
#include stdio.hint main() {     int count;     FILE myFi.pdf#include stdio.hint main() {     int count;     FILE myFi.pdf
#include stdio.hint main() {     int count;     FILE myFi.pdf
 
struct procedure {    Date dateOfProcedure;    int procedureID.pdf
struct procedure {    Date dateOfProcedure;    int procedureID.pdfstruct procedure {    Date dateOfProcedure;    int procedureID.pdf
struct procedure {    Date dateOfProcedure;    int procedureID.pdf
 
DSA.pdf
DSA.pdfDSA.pdf
DSA.pdf
 
9.C Programming
9.C Programming9.C Programming
9.C Programming
 
(Meta 5) ejemplo vectores dev c++
(Meta 5) ejemplo vectores dev c++ (Meta 5) ejemplo vectores dev c++
(Meta 5) ejemplo vectores dev c++
 
(Meta 5) ejemplo vectores 2 dev c++
(Meta 5) ejemplo vectores 2 dev c++ (Meta 5) ejemplo vectores 2 dev c++
(Meta 5) ejemplo vectores 2 dev c++
 
#include stdafx.h#include iostream#include Stringusing.pdf
#include stdafx.h#include iostream#include Stringusing.pdf#include stdafx.h#include iostream#include Stringusing.pdf
#include stdafx.h#include iostream#include Stringusing.pdf
 
sodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdfsodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdf
 
Complete DB code following the instructions Implement the D.pdf
Complete DB code following the instructions Implement the D.pdfComplete DB code following the instructions Implement the D.pdf
Complete DB code following the instructions Implement the D.pdf
 
__MACOSX._assign3assign3.DS_Store__MACOSXassign3._.D.docx
__MACOSX._assign3assign3.DS_Store__MACOSXassign3._.D.docx__MACOSX._assign3assign3.DS_Store__MACOSXassign3._.D.docx
__MACOSX._assign3assign3.DS_Store__MACOSXassign3._.D.docx
 
#include iostream #include fstream #include map #include.pdf
#include iostream #include fstream #include map #include.pdf#include iostream #include fstream #include map #include.pdf
#include iostream #include fstream #include map #include.pdf
 
program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)
 
I have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdfI have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdf
 
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docxcmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
 
selection_sort..c#include stdio.hheader file input output func.pdf
selection_sort..c#include stdio.hheader file input output func.pdfselection_sort..c#include stdio.hheader file input output func.pdf
selection_sort..c#include stdio.hheader file input output func.pdf
 
Data structures
Data structuresData structures
Data structures
 

More from katherncarlyle

After reading chapter 4, evaluate the history of the Data Encryp.docx
After reading chapter 4, evaluate the history of the Data Encryp.docxAfter reading chapter 4, evaluate the history of the Data Encryp.docx
After reading chapter 4, evaluate the history of the Data Encryp.docx
katherncarlyle
 
After reading Chapter 2 and the Required Resources please discuss th.docx
After reading Chapter 2 and the Required Resources please discuss th.docxAfter reading Chapter 2 and the Required Resources please discuss th.docx
After reading Chapter 2 and the Required Resources please discuss th.docx
katherncarlyle
 
After reading chapters 16 and 17 post a short reflection, approximat.docx
After reading chapters 16 and 17 post a short reflection, approximat.docxAfter reading chapters 16 and 17 post a short reflection, approximat.docx
After reading chapters 16 and 17 post a short reflection, approximat.docx
katherncarlyle
 
After reading chapter 3, analyze the history of Caesar Cypher an.docx
After reading chapter 3, analyze the history of Caesar Cypher an.docxAfter reading chapter 3, analyze the history of Caesar Cypher an.docx
After reading chapter 3, analyze the history of Caesar Cypher an.docx
katherncarlyle
 
After having learned about Cognitive Psychology and Humaistic Psycho.docx
After having learned about Cognitive Psychology and Humaistic Psycho.docxAfter having learned about Cognitive Psychology and Humaistic Psycho.docx
After having learned about Cognitive Psychology and Humaistic Psycho.docx
katherncarlyle
 
Advisory from Professionals Preparing Information .docx
Advisory from Professionals Preparing Information .docxAdvisory from Professionals Preparing Information .docx
Advisory from Professionals Preparing Information .docx
katherncarlyle
 
After completing the assigned readings and watching the provided.docx
After completing the assigned readings and watching the provided.docxAfter completing the assigned readings and watching the provided.docx
After completing the assigned readings and watching the provided.docx
katherncarlyle
 
Advocacy is a vital component of the early childhood professiona.docx
Advocacy is a vital component of the early childhood professiona.docxAdvocacy is a vital component of the early childhood professiona.docx
Advocacy is a vital component of the early childhood professiona.docx
katherncarlyle
 
After completing this weeks assignment...   Share with your classma.docx
After completing this weeks assignment...   Share with your classma.docxAfter completing this weeks assignment...   Share with your classma.docx
After completing this weeks assignment...   Share with your classma.docx
katherncarlyle
 
African Americans men are at a greater risk for developing prostate .docx
African Americans men are at a greater risk for developing prostate .docxAfrican Americans men are at a greater risk for developing prostate .docx
African Americans men are at a greater risk for developing prostate .docx
katherncarlyle
 
Advances over the last few decades have brought innovative and c.docx
Advances over the last few decades have brought innovative and c.docxAdvances over the last few decades have brought innovative and c.docx
Advances over the last few decades have brought innovative and c.docx
katherncarlyle
 
Advocacy is a vital component of the early childhood professional’s .docx
Advocacy is a vital component of the early childhood professional’s .docxAdvocacy is a vital component of the early childhood professional’s .docx
Advocacy is a vital component of the early childhood professional’s .docx
katherncarlyle
 
Advocacy Through LegislationIdentify a problem or .docx
Advocacy Through LegislationIdentify a problem or .docxAdvocacy Through LegislationIdentify a problem or .docx
Advocacy Through LegislationIdentify a problem or .docx
katherncarlyle
 
Advanced pathoRespond to Stacy and Sonia 1 day agoStacy A.docx
Advanced pathoRespond to  Stacy and Sonia 1 day agoStacy A.docxAdvanced pathoRespond to  Stacy and Sonia 1 day agoStacy A.docx
Advanced pathoRespond to Stacy and Sonia 1 day agoStacy A.docx
katherncarlyle
 
After completing the reading this week, we reflect on a few ke.docx
After completing the reading this week, we reflect on a few ke.docxAfter completing the reading this week, we reflect on a few ke.docx
After completing the reading this week, we reflect on a few ke.docx
katherncarlyle
 
Adopting Enterprise Risk Management inToday’s Wo.docx
Adopting Enterprise Risk Management inToday’s Wo.docxAdopting Enterprise Risk Management inToday’s Wo.docx
Adopting Enterprise Risk Management inToday’s Wo.docx
katherncarlyle
 
Addisons diseaseYou may use the textbook as one reference a.docx
Addisons diseaseYou may use the textbook as one reference a.docxAddisons diseaseYou may use the textbook as one reference a.docx
Addisons diseaseYou may use the textbook as one reference a.docx
katherncarlyle
 
AdultGeriatric DepressionIntroduction According to Mace.docx
AdultGeriatric DepressionIntroduction According to Mace.docxAdultGeriatric DepressionIntroduction According to Mace.docx
AdultGeriatric DepressionIntroduction According to Mace.docx
katherncarlyle
 
Adopt-a-Plant Project guidelinesOverviewThe purpose of this.docx
Adopt-a-Plant Project guidelinesOverviewThe purpose of this.docxAdopt-a-Plant Project guidelinesOverviewThe purpose of this.docx
Adopt-a-Plant Project guidelinesOverviewThe purpose of this.docx
katherncarlyle
 
Adolescent development is broad and wide-ranging, including phys.docx
Adolescent development is broad and wide-ranging, including phys.docxAdolescent development is broad and wide-ranging, including phys.docx
Adolescent development is broad and wide-ranging, including phys.docx
katherncarlyle
 

More from katherncarlyle (20)

After reading chapter 4, evaluate the history of the Data Encryp.docx
After reading chapter 4, evaluate the history of the Data Encryp.docxAfter reading chapter 4, evaluate the history of the Data Encryp.docx
After reading chapter 4, evaluate the history of the Data Encryp.docx
 
After reading Chapter 2 and the Required Resources please discuss th.docx
After reading Chapter 2 and the Required Resources please discuss th.docxAfter reading Chapter 2 and the Required Resources please discuss th.docx
After reading Chapter 2 and the Required Resources please discuss th.docx
 
After reading chapters 16 and 17 post a short reflection, approximat.docx
After reading chapters 16 and 17 post a short reflection, approximat.docxAfter reading chapters 16 and 17 post a short reflection, approximat.docx
After reading chapters 16 and 17 post a short reflection, approximat.docx
 
After reading chapter 3, analyze the history of Caesar Cypher an.docx
After reading chapter 3, analyze the history of Caesar Cypher an.docxAfter reading chapter 3, analyze the history of Caesar Cypher an.docx
After reading chapter 3, analyze the history of Caesar Cypher an.docx
 
After having learned about Cognitive Psychology and Humaistic Psycho.docx
After having learned about Cognitive Psychology and Humaistic Psycho.docxAfter having learned about Cognitive Psychology and Humaistic Psycho.docx
After having learned about Cognitive Psychology and Humaistic Psycho.docx
 
Advisory from Professionals Preparing Information .docx
Advisory from Professionals Preparing Information .docxAdvisory from Professionals Preparing Information .docx
Advisory from Professionals Preparing Information .docx
 
After completing the assigned readings and watching the provided.docx
After completing the assigned readings and watching the provided.docxAfter completing the assigned readings and watching the provided.docx
After completing the assigned readings and watching the provided.docx
 
Advocacy is a vital component of the early childhood professiona.docx
Advocacy is a vital component of the early childhood professiona.docxAdvocacy is a vital component of the early childhood professiona.docx
Advocacy is a vital component of the early childhood professiona.docx
 
After completing this weeks assignment...   Share with your classma.docx
After completing this weeks assignment...   Share with your classma.docxAfter completing this weeks assignment...   Share with your classma.docx
After completing this weeks assignment...   Share with your classma.docx
 
African Americans men are at a greater risk for developing prostate .docx
African Americans men are at a greater risk for developing prostate .docxAfrican Americans men are at a greater risk for developing prostate .docx
African Americans men are at a greater risk for developing prostate .docx
 
Advances over the last few decades have brought innovative and c.docx
Advances over the last few decades have brought innovative and c.docxAdvances over the last few decades have brought innovative and c.docx
Advances over the last few decades have brought innovative and c.docx
 
Advocacy is a vital component of the early childhood professional’s .docx
Advocacy is a vital component of the early childhood professional’s .docxAdvocacy is a vital component of the early childhood professional’s .docx
Advocacy is a vital component of the early childhood professional’s .docx
 
Advocacy Through LegislationIdentify a problem or .docx
Advocacy Through LegislationIdentify a problem or .docxAdvocacy Through LegislationIdentify a problem or .docx
Advocacy Through LegislationIdentify a problem or .docx
 
Advanced pathoRespond to Stacy and Sonia 1 day agoStacy A.docx
Advanced pathoRespond to  Stacy and Sonia 1 day agoStacy A.docxAdvanced pathoRespond to  Stacy and Sonia 1 day agoStacy A.docx
Advanced pathoRespond to Stacy and Sonia 1 day agoStacy A.docx
 
After completing the reading this week, we reflect on a few ke.docx
After completing the reading this week, we reflect on a few ke.docxAfter completing the reading this week, we reflect on a few ke.docx
After completing the reading this week, we reflect on a few ke.docx
 
Adopting Enterprise Risk Management inToday’s Wo.docx
Adopting Enterprise Risk Management inToday’s Wo.docxAdopting Enterprise Risk Management inToday’s Wo.docx
Adopting Enterprise Risk Management inToday’s Wo.docx
 
Addisons diseaseYou may use the textbook as one reference a.docx
Addisons diseaseYou may use the textbook as one reference a.docxAddisons diseaseYou may use the textbook as one reference a.docx
Addisons diseaseYou may use the textbook as one reference a.docx
 
AdultGeriatric DepressionIntroduction According to Mace.docx
AdultGeriatric DepressionIntroduction According to Mace.docxAdultGeriatric DepressionIntroduction According to Mace.docx
AdultGeriatric DepressionIntroduction According to Mace.docx
 
Adopt-a-Plant Project guidelinesOverviewThe purpose of this.docx
Adopt-a-Plant Project guidelinesOverviewThe purpose of this.docxAdopt-a-Plant Project guidelinesOverviewThe purpose of this.docx
Adopt-a-Plant Project guidelinesOverviewThe purpose of this.docx
 
Adolescent development is broad and wide-ranging, including phys.docx
Adolescent development is broad and wide-ranging, including phys.docxAdolescent development is broad and wide-ranging, including phys.docx
Adolescent development is broad and wide-ranging, including phys.docx
 

Recently uploaded

PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 

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

  • 1. #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"};
  • 2. 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 {
  • 3. 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);
  • 4. 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;
  • 5. } //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);
  • 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("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 ************************/
  • 13. 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; }
  • 14. } 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))
  • 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 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;
  • 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(" 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() {
  • 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("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 ");
  • 22. 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;
  • 23. 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(); }
  • 24. /* ---------------------- 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)) {
  • 25. //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); }
  • 26. } /*-------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");
  • 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 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)
  • 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 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:
  • 33. 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");
  • 34. } break; case 4: findStudentByName(); break; case 5: addBook(); break; case 6: printAllBooksList(); break; case 7: findBookById1();
  • 36. } 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.