Question: Define a main ( ) to play the game as described. All memory must be released before the program exits. The following functions have already

Define a main() to play the game as described. All memory must be released before the program exits.
The following functions have already been defined as described in the rest of the assignment and should be used! Do not redefine here any of the below functions or replicate their functionality inside your main()!
makeDeck
shuffle
addToPile
deal
showPile
totalPile
hitOrStand
freePile
Note: these tests use a "stacked deck" to get consistent results.
Here are the Helping Functions:
cardT *makeCard(int rank, char suit){
if (suit !='C' && suit !='D' && suit !='H' && suit !='S')
return NULL;
if (rank <1|| rank >13)
return NULL;
struct card *newCard = malloc(sizeof(struct card));
if (newCard == NULL)
return NULL;
newCard->rank = rank;
newCard->suit = suit;
newCard->next = NULL;
return newCard;
}
cardT *addToPile(cardT *pile, cardT *card){
if (card == NULL){
return pile;
} else {
card->next = pile;
return card;
}
}
cardT *makeDeck(void){
cardT *deck = NULL;
char suits[]={'C','D','H','S'};
int rank, i;
for (i =0; i <4; i++){
for (rank =1; rank <=13; rank++){
cardT *newCard = makeCard(rank, suits[i]);
if (newCard != NULL){
deck = addToPile(deck, newCard);
}
}
}
return deck;
}
int totalPile(cardT *pile){
int total =0;
while (pile != NULL){
if (pile->rank >=11 && pile->rank <=13){
total +=10;
} else {
total += pile->rank;
}
pile = pile->next;
}
return total;
}
void showPile(cardT *pile){
while (pile != NULL){
printf("%d%c ", pile->rank, pile->suit);
pile = pile->next;
}
printf("
");
}
cardT *deal(cardT *pile){
if (pile == NULL){
return NULL;
}
if (pile->next == NULL){
return pile;
}
cardT *current = pile;
while (current->next->next != NULL){
current = current->next;
}
cardT *lastCard = current->next;
current->next = NULL;
return lastCard;
}
char hitOrStand(void){
char input[100];
char response;
while (1){
scanf("%s", input);
response = tolower(input[0]);
if (response =='h'){
return 'h';
} else if (response =='s'){
return 's';
}
}
}
void freePile(cardT *pile){
cardT *current = pile;
cardT *next;
while (current != NULL){
next = current->next;
free(current);
current = next;
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!