SlideShare a Scribd company logo
1 of 22
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct book_type {
char
title[100],authorFirstName[100],authorLastName[100];
int year;
float rCost;
}node;
// This function loads a catalogue of books from a user specified
file name.
// Note you need to use malloc inside this function to allocate
the memory
// needed for the catalogue of books.
// After catalogue is allocated and filled up with books loaded
from the file,
// it is returned back to the main program via the book_type *
return type.
// The pointer parameter numBooks is used to pass the number
of books back
// out to the numBooks variable in the main function. This way
the other
// functions will be able to use this variable to find how many
books
// are stored in the catalogue.
struct book_type * loadCatalogue(int * numBooks);
// This function saves catalogue into a user specified text file
void saveCatalogue(struct book_type * bCatalogue, int
numBooks);
// This function displays the catalogue onto the screen.
void displayCatalogue(struct book_type * bCatalogue, int
numBooks);
// This function finds a user specified book or set of books and
displays them
void findBook(struct book_type * bCatalogue, int numBooks);
//This function finds a user specified book or set of books and
deletes them
struct book_type * deleteBook(struct book_type * bCatalogue,
int numBooks);
int main() {
struct book_type * bookCatalogue=NULL;
int numBooks,choice=0;
//This loop goes on untill the user gives 6 as a choice
while(choice!=6){
printf("nChoose one of the following options:n1.
Load catalogue from filen2. Save catalogue to filen3. Display
cataloguen4. Find book from cataloguen5. Delete book from
cataloguen6. Quitn");
scanf("%d",&choice);
fflush(stdin);
switch(choice){
case 1:
bookCatalogue =
loadCatalogue(&numBooks);//calls the load catalogue function
break;
case 2:
saveCatalogue(bookCatalogue,
numBooks);//calls the function to save the catalogue
break;
case 3:
displayCatalogue(bookCatalogue,
numBooks); // calls the function to display the catalogue on
screen
break;
case 4:
findBook(bookCatalogue, numBooks);
//calls the function to search for a book in a catalogue
break;
case 5:
bookCatalogue =
deleteBook(bookCatalogue, numBooks); //calls the function to
delete a book from the catalogue
break;
case 6:
printf("Program will exit nown");
break;
default:
printf("Wrong option selected, please select
againn"); // If user gives an invalid input, ask him to re-enter
break;
}
}
return 0;
}
struct book_type * loadCatalogue(int * numBooks) {
struct book_type *bCatalogue;
char fileName[100],line[100];
int i=0;
FILE *fp;
bCatalogue=(node *)malloc(sizeof(node)); //allocate
memory
printf("Enter the name of the file to open:n");
gets(fileName);// Take filename as input
//fflush(stdin);
fp=fopen(fileName,"r");//opens the file in read only mode
if(fp==NULL){//If file cannot be opened due to some
reason than print the error
perror(fileName);
return NULL;
}
while ( fgets ( line, sizeof(line), fp ) != NULL ) /* read a
line */
{
//First line represents the number of books
if(!i)
{
sscanf(line,"%d",&numBooks);
continue;
}
//Take different attributes of book and place them in
proper variables.
if((i-1)%4==2)
{
sscanf(line,"%s",bCatalogue[i/4].title);
}
//Since first name and last name are in the same line,
we need to split it from ','
else if((i-1)%4==3)
{
char fName[100],lName[100];
int j;
for(j=0;line[j]!=',';j++)
{
fName[j]=line[j];
}
fName[j++]='0';
for(;line[j]!='0';j++)
{
lName[j]=line[j];
}
lName[j]='0';
sscanf(fName,"%s",bCatalogue[i/4].authorFirstName);
sscanf(fName,"%s",bCatalogue[i/4].authorLastName);
}
else if((i-1)%4==0)
{
sscanf(line,"%d",&bCatalogue[i/4].year);
}
else if((i-1)%4==1)
{
sscanf(line,"%f",&bCatalogue[i/4].rCost);
}
i++;
}
fclose ( fp );
return bCatalogue;
}
void saveCatalogue(struct book_type * bCatalogue, int
numBooks) {
if(bCatalogue==NULL)
printf("Please load the the book catalogue firstn");
else
{
char fileName[100], name[200],output[20];
FILE *fp=NULL;
int i=0,j=0,k=0;
printf("Enter the name of the file to save:n");
gets(fileName);
fp=fopen(fileName,"w");//open a new file in write
only mode
if(fp==NULL){
perror(fileName);
}
else
{
sprintf(output,"%d",numBooks);
fputs(output,fp);
fwrite("n", sizeof(char), 1, fp);
while(i<4*numBooks)
{
fputs(bCatalogue[i/4].title,fp);
fwrite("n", sizeof(char), 1, fp);
for(;bCatalogue[i/4].authorFirstName[j]!='0';j++)
name[j]=bCatalogue[i/4].authorFirstName[j];
name[j]=',';
name[++j]=' ';
for(;bCatalogue[i/4].authorLastName[k]!='0';k++,j++)
name[j]=bCatalogue[i/4].authorLastName[k];
name[j]='0';
fputs(name,fp);
fwrite("n", sizeof(char), 1, fp);
sprintf(output,"%d",bCatalogue[i/4].year);
fputs(output,fp);
fwrite("n", sizeof(char), 1, fp);
sprintf(output,"%f",bCatalogue[i/4].rCost);
fputs(output,fp);
fwrite("n", sizeof(char), 1, fp);
i++;
}
}
fclose(fp);//close the file
}
}
void displayCatalogue(struct book_type * bCatalogue, int
numBooks) {
if(bCatalogue==NULL)
printf("Please load the the book catalogue firstn");
else
{
int i=0;
printf("Number of books in catalogue = %dn----------
-----------------------------------------------------n",numBooks);
while(i<numBooks)
{
printf("Title: %snAuthor: %s %snYear of
publication: %dnReplacement cost: $%fn-------------------------
--------------------------------------
n",bCatalogue[i].title,bCatalogue[i].authorFirstName,bCatalogu
e[i].authorLastName,bCatalogue[i].year,bCatalogue[i].rCost);
i++;
}
}
}
void findBook(struct book_type * bCatalogue, int numBooks) {
if(bCatalogue==NULL)
printf("Please load the the book catalogue firstn");
else
{
int flag=0,i=0,choice=0;
char find[100];
printf("nChoose one of the following options:n1.
Specify book titlen2. Specify author first namen3. Specify
author last namen");
scanf("%d",&choice);
if(choice==1)
{
printf("Enter book title you want to search
forn");
gets(find);
while(i<numBooks)
{
if(!(strcmpi(find,bCatalogue[i].title)))
{
displayCatalogue(&bCatalogue[i],1);
flag=1;
}
i++;
}
}
else if(choice==2){
printf("Enter author first name that you want to
search forn");
gets(find);
while(i<numBooks)
{
if(!(strcmpi(find,bCatalogue[i].authorFirstName)))
{
displayCatalogue(&bCatalogue[i],1);
flag=1;
}
i++;
}
}
else if(choice==3){
printf("Enter author last name that you want to
search forn");
gets(find);
while(i<numBooks)
{
if(!(strcmpi(find,bCatalogue[i].authorLastName)))
{
displayCatalogue(&bCatalogue[i],1);
flag=1;
}
i++;
}
}
else
printf("Wrong choicen");
if(flag==0)
printf("No search result foundn");
}
}
struct book_type * deleteBook(struct book_type * bCatalogue,
int numBooks) {
if(bCatalogue==NULL)
printf("Please load the the book catalogue firstn");
else
{
int flag=0,i=0,j=0,choice;
char find[100];
struct book_type *bCatalogue1;
bCatalogue1=(node *)malloc(sizeof(node));
printf("nChoose one of the following options:n1.
Specify book titlen2. Specify author first namen3. Specify
author last namen");
scanf("%d",&choice);
if(choice==1)
{
printf("Enter book title you want to search
forn");
gets(find);
while(i<numBooks)
{
if(!(strcmpi(find,bCatalogue[i].title)))
{
displayCatalogue(&bCatalogue[i],1);
flag=1;
}
else
{
bCatalogue1[j]=bCatalogue[i];//add
book if the user doesnot specified this book to be deleted
j++;
}
i++;
}
}
else if(choice==2){
printf("Enter author first name that you want to
search forn");
gets(find);
while(i<numBooks)
{
if(!(strcmpi(find,bCatalogue[i].authorFirstName)))
{
displayCatalogue(&bCatalogue[i],1);
flag=1;
}
else
{
bCatalogue1[j]=bCatalogue[i];//add
book if the user doesnot specified this book to be deleted
j++;
}
i++;
}
}
else if(choice==3){
printf("Enter author last name that you want to
search forn");
gets(find);
while(i<numBooks)
{
if(!(strcmpi(find,bCatalogue[i].authorLastName)))
{
displayCatalogue(&bCatalogue[i],1);
flag=1;
}
else
{
bCatalogue1[j]=bCatalogue[i];//add
book if the user doesnot specified this book to be deleted
j++;
}
i++;
}
}
else
printf("Wrong choicen");
if(flag==0)
printf("No search result foundn");
return bCatalogue1;
}
return NULL;
}
1
<Name>
<Course>
<Date>
<Instructor>
Typing Template for GCU Papers for Lower Division Courses
Formatting: This is an electronic template for papers written in
GCU style. The purpose of the template is to help you follow
the basic writing expectations for beginning your coursework at
GCU. Margins are set at 1 inch for top, bottom, left, and right.
Each paragraph is indented five spaces. It is best to use the tab
key to indent. The line spacing is double throughout the paper,
even on the reference page. The font style used in this template
is Times New Roman. The font size is 12. When you are ready
to write, and after having read these instructions completely,
you can delete these directions and start typing. The formatting
should stay the same. If you have any questions, please consult
with your instructor.
Citations: Citations are used to reference material from another
source. When paraphrasing material from another source (such
as a book, journal, Web site, etc.), include the author’s last
name and the publication year in parentheses.When directly
quoting material word-for-word from another source, use
quotation marks and include the page number after the author’s
last name and year.
Using citations to give credit to others whose ideas or words
you have used is an essential requirement to avoid issues of
plagiarism. Just as you would never steal someone else’s car,
you should not steal their words either. To avoid potential
problems, always be sure to cite your sources by referring to the
author’s last name and the year of publication in parentheses at
the end of the sentence, such as (Daresh, 2004) and page
numbers if you are using word-for-word materials, such as
“There are no simple strategies for accomplishing successful
transitions, but we do know a great deal about how to get off to
a good start” (King & Blumer, 2000, p. 356).
The reference list should appear at the end of a paper (see the
next page). It provides the information necessary for a reader to
locate and retrieve any source you cite in the body of the paper.
Each source you cite in the paper must appear in your reference
list; likewise, each entry in the reference list must be cited in
your text. A sample reference page is included below; this page
includes examples of how to format different reference types
(e.g., books, journal articles, a Web site).
References
Arnold, J. B., & Dodge, H. W. (1994). Room for all. The
American School Board Journal, 181(10), 22-26.
Black, J. A., & English, F. W. (1986). What they don’t tell you
in schools of education about school administration. Lancaster,
PA: Technomic.
Daresh, J. C. (2004). Beginning the assistant principalship: A
practical guide for newschool administrators. Thousand Oaks,
CA: Corwin.
King, M., & Blumer, I. (2000). A good start. Phi Delta Kappan,
81(5), 356-360.
USA swimming. (n.d.). Retrieved August 24, 2004, from
http://www.usaswimming.org/usasweb/DesktopDefault.aspx

More Related Content

Similar to #include stdio.h#include stdlib.h#include string.ht.docx

Seu primeiro app Android e iOS com Compose Multiplatform
Seu primeiro app Android e iOS com Compose MultiplatformSeu primeiro app Android e iOS com Compose Multiplatform
Seu primeiro app Android e iOS com Compose MultiplatformNelson Glauber Leal
 
C programming(part 3)
C programming(part 3)C programming(part 3)
C programming(part 3)SURBHI SAROHA
 
First java-server-faces-tutorial-en
First java-server-faces-tutorial-enFirst java-server-faces-tutorial-en
First java-server-faces-tutorial-entechbed
 
SAX, DOM & JDOM parsers for beginners
SAX, DOM & JDOM parsers for beginnersSAX, DOM & JDOM parsers for beginners
SAX, DOM & JDOM parsers for beginnersHicham QAISSI
 
STC 2016 Programming Language Storytime
STC 2016 Programming Language StorytimeSTC 2016 Programming Language Storytime
STC 2016 Programming Language StorytimeSarah Kiniry
 
Generation_XSD_Article - Part 3.pdf
Generation_XSD_Article - Part 3.pdfGeneration_XSD_Article - Part 3.pdf
Generation_XSD_Article - Part 3.pdfDavid Harrison
 
Link.javaLink.javapackage com.bookstore.domain.model;import .docx
Link.javaLink.javapackage com.bookstore.domain.model;import .docxLink.javaLink.javapackage com.bookstore.domain.model;import .docx
Link.javaLink.javapackage com.bookstore.domain.model;import .docxSHIVA101531
 
Assignment2 A
Assignment2 AAssignment2 A
Assignment2 AMahmoud
 
Library Project Marcelo Salvador
Library Project Marcelo SalvadorLibrary Project Marcelo Salvador
Library Project Marcelo SalvadorDomingos Salvador
 
Functional Java 8 in everyday life
Functional Java 8 in everyday lifeFunctional Java 8 in everyday life
Functional Java 8 in everyday lifeAndrea Iacono
 
Lk module4 structures
Lk module4 structuresLk module4 structures
Lk module4 structuresKrishna Nanda
 
Constructors & Destructors [Compatibility Mode].pdf
Constructors & Destructors [Compatibility Mode].pdfConstructors & Destructors [Compatibility Mode].pdf
Constructors & Destructors [Compatibility Mode].pdfLadallaRajKumar
 
cake phptutorial
cake phptutorialcake phptutorial
cake phptutorialice27
 
The Django Book - Chapter 6 the django admin site
The Django Book - Chapter 6  the django admin siteThe Django Book - Chapter 6  the django admin site
The Django Book - Chapter 6 the django admin siteVincent Chien
 

Similar to #include stdio.h#include stdlib.h#include string.ht.docx (20)

Seu primeiro app Android e iOS com Compose Multiplatform
Seu primeiro app Android e iOS com Compose MultiplatformSeu primeiro app Android e iOS com Compose Multiplatform
Seu primeiro app Android e iOS com Compose Multiplatform
 
C programming(part 3)
C programming(part 3)C programming(part 3)
C programming(part 3)
 
structure.ppt
structure.pptstructure.ppt
structure.ppt
 
First java-server-faces-tutorial-en
First java-server-faces-tutorial-enFirst java-server-faces-tutorial-en
First java-server-faces-tutorial-en
 
SAX, DOM & JDOM parsers for beginners
SAX, DOM & JDOM parsers for beginnersSAX, DOM & JDOM parsers for beginners
SAX, DOM & JDOM parsers for beginners
 
Javadoc guidelines
Javadoc guidelinesJavadoc guidelines
Javadoc guidelines
 
88 c-programs
88 c-programs88 c-programs
88 c-programs
 
STC 2016 Programming Language Storytime
STC 2016 Programming Language StorytimeSTC 2016 Programming Language Storytime
STC 2016 Programming Language Storytime
 
Generation_XSD_Article - Part 3.pdf
Generation_XSD_Article - Part 3.pdfGeneration_XSD_Article - Part 3.pdf
Generation_XSD_Article - Part 3.pdf
 
Link.javaLink.javapackage com.bookstore.domain.model;import .docx
Link.javaLink.javapackage com.bookstore.domain.model;import .docxLink.javaLink.javapackage com.bookstore.domain.model;import .docx
Link.javaLink.javapackage com.bookstore.domain.model;import .docx
 
Assignment2 A
Assignment2 AAssignment2 A
Assignment2 A
 
Library Project Marcelo Salvador
Library Project Marcelo SalvadorLibrary Project Marcelo Salvador
Library Project Marcelo Salvador
 
Functional Java 8 in everyday life
Functional Java 8 in everyday lifeFunctional Java 8 in everyday life
Functional Java 8 in everyday life
 
Lk module4 structures
Lk module4 structuresLk module4 structures
Lk module4 structures
 
Constructors & Destructors [Compatibility Mode].pdf
Constructors & Destructors [Compatibility Mode].pdfConstructors & Destructors [Compatibility Mode].pdf
Constructors & Destructors [Compatibility Mode].pdf
 
cake phptutorial
cake phptutorialcake phptutorial
cake phptutorial
 
The Django Book - Chapter 6 the django admin site
The Django Book - Chapter 6  the django admin siteThe Django Book - Chapter 6  the django admin site
The Django Book - Chapter 6 the django admin site
 
Pointers in C and Dynamic Memory Allocation
Pointers in C and Dynamic Memory AllocationPointers in C and Dynamic Memory Allocation
Pointers in C and Dynamic Memory Allocation
 
U5 SPC.pptx
U5 SPC.pptxU5 SPC.pptx
U5 SPC.pptx
 
U5 SPC.pptx
U5 SPC.pptxU5 SPC.pptx
U5 SPC.pptx
 

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

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
 
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
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
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
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
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
 
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
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
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
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
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
 
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
 

Recently uploaded (20)

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
 
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)
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
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...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
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Ữ Â...
 
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
 
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...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
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
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
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
 
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
 

#include stdio.h#include stdlib.h#include string.ht.docx

  • 1. #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct book_type { char title[100],authorFirstName[100],authorLastName[100]; int year; float rCost; }node; // This function loads a catalogue of books from a user specified file name. // Note you need to use malloc inside this function to allocate the memory // needed for the catalogue of books. // After catalogue is allocated and filled up with books loaded from the file, // it is returned back to the main program via the book_type * return type. // The pointer parameter numBooks is used to pass the number
  • 2. of books back // out to the numBooks variable in the main function. This way the other // functions will be able to use this variable to find how many books // are stored in the catalogue. struct book_type * loadCatalogue(int * numBooks); // This function saves catalogue into a user specified text file void saveCatalogue(struct book_type * bCatalogue, int numBooks); // This function displays the catalogue onto the screen. void displayCatalogue(struct book_type * bCatalogue, int numBooks); // This function finds a user specified book or set of books and displays them void findBook(struct book_type * bCatalogue, int numBooks);
  • 3. //This function finds a user specified book or set of books and deletes them struct book_type * deleteBook(struct book_type * bCatalogue, int numBooks); int main() { struct book_type * bookCatalogue=NULL; int numBooks,choice=0; //This loop goes on untill the user gives 6 as a choice while(choice!=6){ printf("nChoose one of the following options:n1. Load catalogue from filen2. Save catalogue to filen3. Display cataloguen4. Find book from cataloguen5. Delete book from cataloguen6. Quitn"); scanf("%d",&choice); fflush(stdin); switch(choice){ case 1: bookCatalogue = loadCatalogue(&numBooks);//calls the load catalogue function
  • 4. break; case 2: saveCatalogue(bookCatalogue, numBooks);//calls the function to save the catalogue break; case 3: displayCatalogue(bookCatalogue, numBooks); // calls the function to display the catalogue on screen break; case 4: findBook(bookCatalogue, numBooks); //calls the function to search for a book in a catalogue break; case 5: bookCatalogue = deleteBook(bookCatalogue, numBooks); //calls the function to delete a book from the catalogue break; case 6: printf("Program will exit nown");
  • 5. break; default: printf("Wrong option selected, please select againn"); // If user gives an invalid input, ask him to re-enter break; } } return 0; } struct book_type * loadCatalogue(int * numBooks) { struct book_type *bCatalogue; char fileName[100],line[100]; int i=0; FILE *fp; bCatalogue=(node *)malloc(sizeof(node)); //allocate memory printf("Enter the name of the file to open:n"); gets(fileName);// Take filename as input
  • 6. //fflush(stdin); fp=fopen(fileName,"r");//opens the file in read only mode if(fp==NULL){//If file cannot be opened due to some reason than print the error perror(fileName); return NULL; } while ( fgets ( line, sizeof(line), fp ) != NULL ) /* read a line */ { //First line represents the number of books if(!i) { sscanf(line,"%d",&numBooks); continue; } //Take different attributes of book and place them in proper variables. if((i-1)%4==2)
  • 7. { sscanf(line,"%s",bCatalogue[i/4].title); } //Since first name and last name are in the same line, we need to split it from ',' else if((i-1)%4==3) { char fName[100],lName[100]; int j; for(j=0;line[j]!=',';j++) { fName[j]=line[j]; } fName[j++]='0'; for(;line[j]!='0';j++) { lName[j]=line[j]; } lName[j]='0';
  • 9. void saveCatalogue(struct book_type * bCatalogue, int numBooks) { if(bCatalogue==NULL) printf("Please load the the book catalogue firstn"); else { char fileName[100], name[200],output[20]; FILE *fp=NULL; int i=0,j=0,k=0; printf("Enter the name of the file to save:n"); gets(fileName); fp=fopen(fileName,"w");//open a new file in write only mode if(fp==NULL){ perror(fileName); } else { sprintf(output,"%d",numBooks);
  • 10. fputs(output,fp); fwrite("n", sizeof(char), 1, fp); while(i<4*numBooks) { fputs(bCatalogue[i/4].title,fp); fwrite("n", sizeof(char), 1, fp); for(;bCatalogue[i/4].authorFirstName[j]!='0';j++) name[j]=bCatalogue[i/4].authorFirstName[j]; name[j]=','; name[++j]=' '; for(;bCatalogue[i/4].authorLastName[k]!='0';k++,j++) name[j]=bCatalogue[i/4].authorLastName[k]; name[j]='0'; fputs(name,fp); fwrite("n", sizeof(char), 1, fp); sprintf(output,"%d",bCatalogue[i/4].year);
  • 11. fputs(output,fp); fwrite("n", sizeof(char), 1, fp); sprintf(output,"%f",bCatalogue[i/4].rCost); fputs(output,fp); fwrite("n", sizeof(char), 1, fp); i++; } } fclose(fp);//close the file } } void displayCatalogue(struct book_type * bCatalogue, int numBooks) { if(bCatalogue==NULL) printf("Please load the the book catalogue firstn"); else {
  • 12. int i=0; printf("Number of books in catalogue = %dn---------- -----------------------------------------------------n",numBooks); while(i<numBooks) { printf("Title: %snAuthor: %s %snYear of publication: %dnReplacement cost: $%fn------------------------- -------------------------------------- n",bCatalogue[i].title,bCatalogue[i].authorFirstName,bCatalogu e[i].authorLastName,bCatalogue[i].year,bCatalogue[i].rCost); i++; } } } void findBook(struct book_type * bCatalogue, int numBooks) { if(bCatalogue==NULL) printf("Please load the the book catalogue firstn"); else { int flag=0,i=0,choice=0;
  • 13. char find[100]; printf("nChoose one of the following options:n1. Specify book titlen2. Specify author first namen3. Specify author last namen"); scanf("%d",&choice); if(choice==1) { printf("Enter book title you want to search forn"); gets(find); while(i<numBooks) { if(!(strcmpi(find,bCatalogue[i].title))) { displayCatalogue(&bCatalogue[i],1); flag=1; } i++; }
  • 14. } else if(choice==2){ printf("Enter author first name that you want to search forn"); gets(find); while(i<numBooks) { if(!(strcmpi(find,bCatalogue[i].authorFirstName))) { displayCatalogue(&bCatalogue[i],1); flag=1; } i++; } } else if(choice==3){ printf("Enter author last name that you want to search forn");
  • 16. struct book_type * deleteBook(struct book_type * bCatalogue, int numBooks) { if(bCatalogue==NULL) printf("Please load the the book catalogue firstn"); else { int flag=0,i=0,j=0,choice; char find[100]; struct book_type *bCatalogue1; bCatalogue1=(node *)malloc(sizeof(node)); printf("nChoose one of the following options:n1. Specify book titlen2. Specify author first namen3. Specify author last namen"); scanf("%d",&choice); if(choice==1) { printf("Enter book title you want to search forn"); gets(find); while(i<numBooks)
  • 17. { if(!(strcmpi(find,bCatalogue[i].title))) { displayCatalogue(&bCatalogue[i],1); flag=1; } else { bCatalogue1[j]=bCatalogue[i];//add book if the user doesnot specified this book to be deleted j++; } i++; } } else if(choice==2){ printf("Enter author first name that you want to search forn"); gets(find);
  • 18. while(i<numBooks) { if(!(strcmpi(find,bCatalogue[i].authorFirstName))) { displayCatalogue(&bCatalogue[i],1); flag=1; } else { bCatalogue1[j]=bCatalogue[i];//add book if the user doesnot specified this book to be deleted j++; } i++; } } else if(choice==3){ printf("Enter author last name that you want to search forn");
  • 20. printf("Wrong choicen"); if(flag==0) printf("No search result foundn"); return bCatalogue1; } return NULL; } 1 <Name> <Course> <Date> <Instructor> Typing Template for GCU Papers for Lower Division Courses Formatting: This is an electronic template for papers written in GCU style. The purpose of the template is to help you follow the basic writing expectations for beginning your coursework at GCU. Margins are set at 1 inch for top, bottom, left, and right. Each paragraph is indented five spaces. It is best to use the tab key to indent. The line spacing is double throughout the paper, even on the reference page. The font style used in this template is Times New Roman. The font size is 12. When you are ready to write, and after having read these instructions completely, you can delete these directions and start typing. The formatting
  • 21. should stay the same. If you have any questions, please consult with your instructor. Citations: Citations are used to reference material from another source. When paraphrasing material from another source (such as a book, journal, Web site, etc.), include the author’s last name and the publication year in parentheses.When directly quoting material word-for-word from another source, use quotation marks and include the page number after the author’s last name and year. Using citations to give credit to others whose ideas or words you have used is an essential requirement to avoid issues of plagiarism. Just as you would never steal someone else’s car, you should not steal their words either. To avoid potential problems, always be sure to cite your sources by referring to the author’s last name and the year of publication in parentheses at the end of the sentence, such as (Daresh, 2004) and page numbers if you are using word-for-word materials, such as “There are no simple strategies for accomplishing successful transitions, but we do know a great deal about how to get off to a good start” (King & Blumer, 2000, p. 356). The reference list should appear at the end of a paper (see the next page). It provides the information necessary for a reader to locate and retrieve any source you cite in the body of the paper. Each source you cite in the paper must appear in your reference list; likewise, each entry in the reference list must be cited in your text. A sample reference page is included below; this page includes examples of how to format different reference types (e.g., books, journal articles, a Web site). References Arnold, J. B., & Dodge, H. W. (1994). Room for all. The American School Board Journal, 181(10), 22-26. Black, J. A., & English, F. W. (1986). What they don’t tell you in schools of education about school administration. Lancaster, PA: Technomic.
  • 22. Daresh, J. C. (2004). Beginning the assistant principalship: A practical guide for newschool administrators. Thousand Oaks, CA: Corwin. King, M., & Blumer, I. (2000). A good start. Phi Delta Kappan, 81(5), 356-360. USA swimming. (n.d.). Retrieved August 24, 2004, from http://www.usaswimming.org/usasweb/DesktopDefault.aspx