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 makeCardint rank, char suit
if suit C && suit D && suit H && suit S
return NULL;
if rank rank
return NULL;
struct card newCard mallocsizeofstruct card;
if newCard NULL
return NULL;
newCardrank rank;
newCardsuit suit;
newCardnext NULL;
return newCard;
cardT addToPilecardT pile cardT card
if card NULL
return pile;
else
cardnext pile;
return card;
cardT makeDeckvoid
cardT deck NULL;
char suitsCDHS;
int rank, i;
for i ; i ; i
for rank ; rank ; rank
cardT newCard makeCardrank suitsi;
if newCard NULL
deck addToPiledeck newCard;
return deck;
int totalPilecardT pile
int total ;
while pile NULL
if pilerank && pilerank
total ;
else
total pilerank;
pile pilenext;
return total;
void showPilecardT pile
while pile NULL
printfdc pilerank, pilesuit;
pile pilenext;
printf
;
cardT dealcardT pile
if pile NULL
return NULL;
if pilenext NULL
return pile;
cardT current pile;
while currentnextnext NULL
current currentnext;
cardT lastCard currentnext;
currentnext NULL;
return lastCard;
char hitOrStandvoid
char input;
char response;
while
scanfs input;
response tolowerinput;
if response h
return h;
else if response s
return s;
void freePilecardT pile
cardT current pile;
cardT next;
while current NULL
next currentnext;
freecurrent;
current next;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
