SlideShare a Scribd company logo
1 of 36
#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)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.docxajoy21
 
#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.pdfanithareadymade
 
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.pdfanonaeon
 
(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.pdfanokhilalmobile
 
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).pdfMuhammadMaazShaik
 
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.pdfaccess2future1
 
__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.docxodiliagilby
 
#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.pdfinbox5
 
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 .pdfezzi552
 
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 .docxgordienaysmythe
 
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.pdfanton291
 

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.docxkatherncarlyle
 
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.docxkatherncarlyle
 
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.docxkatherncarlyle
 
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.docxkatherncarlyle
 
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.docxkatherncarlyle
 
Advisory from Professionals Preparing Information .docx
Advisory from Professionals Preparing Information .docxAdvisory from Professionals Preparing Information .docx
Advisory from Professionals Preparing Information .docxkatherncarlyle
 
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.docxkatherncarlyle
 
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.docxkatherncarlyle
 
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.docxkatherncarlyle
 
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 .docxkatherncarlyle
 
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.docxkatherncarlyle
 
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 .docxkatherncarlyle
 
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 .docxkatherncarlyle
 
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.docxkatherncarlyle
 
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.docxkatherncarlyle
 
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.docxkatherncarlyle
 
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.docxkatherncarlyle
 
AdultGeriatric DepressionIntroduction According to Mace.docx
AdultGeriatric DepressionIntroduction According to Mace.docxAdultGeriatric DepressionIntroduction According to Mace.docx
AdultGeriatric DepressionIntroduction According to Mace.docxkatherncarlyle
 
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.docxkatherncarlyle
 
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.docxkatherncarlyle
 

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

Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 

Recently uploaded (20)

Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 

#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.