Shuffle linked list in C???
I have to create a program that plays the game of UNO. We have to create the deck using a linked list, and also be able to shuffle the cards. I have a hard time fully understanding linked lists. I found a shuffle and swap function online and I am currently using it in my code, but I think the shuffle function is off. The output is only "shuffling" large portions of the deck, not each individual card.
If you can see what is wrong with my code and correct it, or even offer a better shuffle function, that would be awesome!
Here is a picture of my code:
#include
10 #include 11 #include 12 13 typedef struct card s f 14 15 16 17 18card; 19 20 void print_list(card headp) char suit [71; int value; char action[15]; struct card s *pt while (headp NULL){ %s != ", headp->suit, headp->value, headp->action); printf("%s %d headp headp->pt: 25 printf("n") 27 void swap_cards(card* source, card target) if (source != NULL && target != NULL){ char tmpSuit[71; strcpy(&tmpSuit, source->suit) int tmpVal = source->value; char tmpAct[15] strcpy(&tmpAct, source->action); strcpy(source->suit, target->suit); source->value arget->value; strcpy(source->action, target->action); strcpy(target->suit, &tmpSuit) target->value mpval ; strcpy(target->action, &tmpAct); 30 Incompatible pointer types pas 32 Incompatible pointer types pass 35 Incompatible pointer types passing 38 Incompatible pointer types passing 'cl 40 41 44 //FIXME Kind of shuffles cards. More like reorganizes some parts, doesn't randomly shuffle suffiently 45 void shuffle cards (card *deck) intn1880, i; int decksize- 186; card *tmp = deck ; while (n>0) while (tmp != NULL){ card *target- deck; i = rand ( )%decksize; 52 while (1--&& tmp != NULL){ 54 target = target->pt; swap_cards(tmp, target) tmp = tmp->pt; #include 10 #include 11 #include 12 13 typedef struct card s f 14 15 16 17 18card; 19 20 void print_list(card headp) char suit [71; int value; char action[15]; struct card s *pt while (headp NULL){ %s != ", headp->suit, headp->value, headp->action); printf("%s %d headp headp->pt: 25 printf("n") 27 void swap_cards(card* source, card target) if (source != NULL && target != NULL){ char tmpSuit[71; strcpy(&tmpSuit, source->suit) int tmpVal = source->value; char tmpAct[15] strcpy(&tmpAct, source->action); strcpy(source->suit, target->suit); source->value arget->value; strcpy(source->action, target->action); strcpy(target->suit, &tmpSuit) target->value mpval ; strcpy(target->action, &tmpAct); 30 Incompatible pointer types pas 32 Incompatible pointer types pass 35 Incompatible pointer types passing 38 Incompatible pointer types passing 'cl 40 41 44 //FIXME Kind of shuffles cards. More like reorganizes some parts, doesn't randomly shuffle suffiently 45 void shuffle cards (card *deck) intn1880, i; int decksize- 186; card *tmp = deck ; while (n>0) while (tmp != NULL){ card *target- deck; i = rand ( )%decksize; 52 while (1--&& tmp != NULL){ 54 target = target->pt; swap_cards(tmp, target) tmp = tmp->pt