Question
Please write in C code (Not C++) Please comment code for important steps, THANKS! Also use linked list Code so far: #define _CRT_SECURE_NO_WARNINGS #include #include
Please write in C code (Not C++)
Please comment code for important steps, THANKS!
Also use linked list
Code so far:
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
typedef struct card_s {
char face[3];
char suit[10];
struct card_s *next;
}card;
void print_deck(card *prt_srt) {
int pcount = 0;
printf("Create a 52-card deck ");
// go through the list until the null
while (prt_srt != NULL) {
printf("%s of %s\t", prt_srt->face, prt_srt->suit);
pcount++;
if (pcount == 8) {
printf(" ");
pcount = 0;
}
prt_srt = prt_srt->next;
}
} // end of print function
void ShuffleCard(card**headp) {
int i, a, b, count, temp;
card *card1 = NULL;
card *card2 = NULL;
// Repeat shuffle 1000 times
for (i = 0; i
a = rand() % 52;
b = rand() % 52;
card1 = *headp;
card2 = *headp;
while (count
count++;
card1 = card1->next;
}
//Reset count to 0
count = 0;
while (count
count++;
card2 = card2->next;
}
// Swap cards
temp = card1;
card1 = card2;
card2 = temp;
}
//Dont know how to print deck after shuffle is done??
}
int main(void) {
card *temp;
card *headp = NULL; card *tail = NULL;
FILE *inp;
//Open file
inp = fopen("Cards_Deck.txt", "r");
if (inp == NULL) {
printf("File not found ");
return 0;
}
temp = (card *)malloc(sizeof(card));
while (fscanf(inp, "%s%s", temp->face, temp->suit) != EOF) {
if (headp == NULL) {
headp = temp;
}
else {
tail->next = temp;
}
tail = temp;
tail->next = NULL;
temp = (card *)malloc(sizeof(card));
} // end of while loop
// After completing the reading of all items, send to print
print_deck(headp);
//shuffle_card(headp);
fclose(inp);
return 0;
} // end of int main
Write a C program to 1) Create a full deck of 52 cards that are in order. In other words, for each of the four suits, the cards should be in order from Ace (1) through King (13). each card is consisted of a suit [clubs (+),spades (*),hearts (), or diamonds (*) a face (1(Ace)-10, Jacks (J), Queens (Q), and Kings (K)) To simulate the deck of 52 cards, and each of the hands, your team MUST use a dynamic list of cards with the following struct type: typedef struct card s{ char suit; int face; struct card_s *next; ) card; Print the deck that you create 2) Shuffle the deck (52 cards). Note: Your code must have a ShuffleCard() function and should work with any size deck of cards, i.e. shuffling 53 cards, 20 cards or 5 cards One algorithm that you may use to shuffle the deckStep 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