Question
Description: - Change the struct card from the attached file to struct book with the following fields: char array author char array bookName int for
Description:
- Change the struct card from the attached file to struct book with the following fields:
char array author
char array bookName
int for the number of pages
double cost
Modify to reflect the changes from card to book
variables
function prototypes
functions calls
For the array of books use the variable name booklist instead of manycards
card.txt contains:
/* Tami Sorgente
* COP2220 Intro to Programming in C
* user defined struct example
*/
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#define SIZE 20
typedef struct{
char face[SIZE];
char suit[SIZE];
int pointV;
}card;
//Function Prototypes
// fills the data fields of a card instance
//returns the filled card
card FillCard();
//fills the data fields of a card instance
//by reference using a pointer to a card
void FillCardPtr(card *cardptr);
//fills an array of cards
void FillCardArray(card arrayC[], int *size);
//displays one card
void DisplayCard(card anyCard);
int main()
{
//Declare variables
card myCard, myCard1, myCard2;
card manyCards[SIZE];
int cSize;
int i;
//Fill structures with a function
myCard = FillCard();
myCard1 = FillCard();
//print using display function
printf(" ---------Display myCard ");
DisplayCard(myCard);
printf(" ---------Display myCard1 ");
DisplayCard(myCard1);
//Fill structure using pointers and dispay it
FillCardPtr(&myCard2);
printf(" ---------Display myCard2 ");
DisplayCard(myCard2);
//Fill the array with the function
printf(" ---------Fill array manyCards ");
FillCardArray(manyCards, &cSize);
//display an array of cards
printf(" ---------Display array manyCards ");
for(i=0;i { DisplayCard(manyCards[i]); } return 0; } //Function Definitions // fills the data fields of a card instance //returns the filled card card FillCard() { //Declare local variables card tempC; //prompt and get information printf(" please enter the face of your card: "); scanf("%s", tempC.face); //print to check printf("face: %s ", tempC.face); //prompt and get information printf(" please enter the suit of your card: "); scanf("%s", tempC.suit); //print to check printf("suit: %s ", tempC.suit); //prompt and get information printf(" please enter the point value of your card: "); scanf("%d", &tempC.pointV); printf("point value: %d ", tempC.pointV); return tempC; } //displays one card void DisplayCard(card anyCard) { printf(" face: %s ", anyCard.face); printf("suit: %s ", anyCard.suit); printf("point value: %d ", anyCard.pointV); } //fills the data fields of a card instance //by reference using a pointer to a card void FillCardPtr(card *cardptr) { //prompt and get information printf(" please enter the face of your card: "); scanf("%s", (*cardptr).face); //prompt and get information printf(" please enter the suit of your card: "); scanf("%s", cardptr->suit); //prompt and get information printf(" please enter the point value of your card: "); scanf("%d", &(*cardptr).pointV); } //fills an array of cards void FillCardArray(card arrayC[], int *size) { int i; //prompt the user printf(" enter the number of cards: "); scanf("%d", size); //print to check printf("size: %d ", *size); for (i=0; i < *size; i++) { printf("enter face: "); scanf("%s", arrayC[i].face); printf("enter suit: "); scanf("%s", arrayC[i].suit); printf("enter point value: "); scanf("%d", &arrayC[i].pointV); } } /*please enter the face of your card: king face: king please enter the suit of your card: spade suit: spade please enter the point value of your card: 10 point value: 10 please enter the face of your card: three face: three please enter the suit of your card: heart suit: heart please enter the point value of your card: 3 point value: 3 ---------Display myCard face: king suit: spade point value: 10 ---------Display myCard1 face: three suit: heart point value: 3 please enter the face of your card: king please enter the suit of your card: diamonds please enter the point value of your card: 10 ---------Display myCard2 face: king suit: diamonds point value: 10 ---------Fill array manyCards enter the number of cards: 3 size: 3 enter face: jack enter suit: clubs enter point value: 10 enter face: four enter suit: hearts enter point value: 4 enter face: ace enter suit: spades enter point value: 11 ---------Display array manyCards face: jack suit: clubs point value: 10 face: four suit: hearts point value: 4 face: ace suit: spades point value: 11 Press any key to continue . . .*/
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started