Question: I need help fixing my swap fuction in my program. I'm not sure what to do to fix it. The code is for shuffling a
I need help fixing my swap fuction in my program. I'm not sure what to do to fix it. The code is for shuffling a deck of uno cards.
This is the error list:

This is my code:
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
#include
#define RED 2
#define BLUE 1
#define GREEN 4
#define YELLOW 6
#define RAINBOW 3
#define REVERSE 10
#define SKIP 11
#define DRAW 12
#define WILD 13
#define WILD4 14
typedef struct card_s{
char suit[7];
int value;
char action[15];
struct card_s *previous,*next, *hr,*hl;
} card;
void printCard(card *h);
void createDeck(FILE*inp, card **hl, card **hr);
//void colorFunct(int color);
//void checkWinner(int winner);
void shuffle(card *hl);
card findCard(card hl, int number);
void swap(card *temp, card *temp2);
int main(void) {
int number = 0;
int winner = 0;
FILE*inp;
inp = fopen("deck.txt", "r");
card *hl = NULL;
card *hr = NULL;
printf("UNO ");
printf("Press enter to play ");
getch();
createDeck(inp, &hl, &hr);
printCard(hl);
printf("Enter the number of players: ");
//dynamically allocates memory
//function for creating list for each player
printf("Press 1 to shuffle the deck or press 2 to scan file: ");
scanf("%d", &number);
if (number == 1) {
printf(" Shuffling the deck ");
//color function
shuffle(&hl);
printf("Press enter to begin ");
getch();
printCard(hl);
}
else if (number == 2) {
printf("Enter the name of the file ");
//fscanf
}
while (winner != 1) {
//game
}
return 0;
}
void shuffle(card *hl) {
card* temp = NULL;
int number;
int i;
card *temp2 = NULL;
for (i = 0; i
temp = hl;
while (temp != NULL) {
number = rand(1 % 108);
*temp2 = findCard(*hl, number);
swap(temp, temp2);
}
}
}
card findCard(card hl, int number) {
int count = 0;
card* temp;
card* current;
while (count != number) {
current = temp;
temp = temp->next;
++count;
}
return(*current);
}
void swap(card *temp, card *temp2) {
card *pt;
pt = (card*)malloc(sizeof(card));
pt = NULL;
pt->value = temp->value;
pt->suit = temp->suit;
pt->action = temp->action;
temp->value = temp2->value;
temp->suit = temp2->suit;
temp->action = temp2->action;
temp2->value = pt->value;
temp2->suit = pt->suit;
temp2->action = pt->action;
}
void createDeck(FILE*inp, card **hl, card **hr) {
card *temp;
card *var = NULL;
temp = (card*)malloc(sizeof(card));
if (*hl == NULL) {
temp->next = NULL;
temp->previous = NULL;
fscanf(inp, "%d", &temp->value);
fscanf(inp, "%s", temp->suit);
fscanf(inp, "%s", temp->action);
//*hlprevious = NULL;
var = temp;
*hl = var;
temp = temp->next;
}
while (!feof(inp)) {
temp = (card*)malloc(sizeof(card));
fscanf(inp, "%d", &temp->value);
fscanf(inp, "%s", temp->suit);
fscanf(inp, "%s", temp->action);
temp->next = NULL;
var->next = temp;
temp = temp->next;
var = var->next;
}
}
void printCard(card *head) {
card *current = head;
while (current != NULL) {
printf("%s %d ", current->suit, current->value);
current = current->next;
}
}
void swap(card *temp, card *temp2) card *pt; pt-(card*)malloc(sizeof (card)); pt NULL; pt-value = temp-walue; pt->suit-temp->suit; pt->action -temp-action; temp->value temp2->value; temp->suit -temp2->suit; temp->action temp2->action; temp2->value -pt>value; temp2-suit- temp2->action = pt-action ; void createDeck (FILE*inp, card **hl, card **hr) card *temp; card *var NULL; temp (card )malloc (sizeof (card)); if (*hlNULL) temp->next NULL; temp->previous = NULL 12 Errors ? 0 of 4 Warnings 0Messages kl Build +IntelliSense Search Error List Description expression must be a modifiable Ivalue expression must be a modifiable Ivalue -': left operand must be l-value -': left operand must be l-value -': left operand must be l-value -': left operand must be l-value -': left operand must be l-value -': left operand must be l-value Project Project3.c Project3.c Project3.c Project3.c Project3.c Project3.c Project3.c Project3.c File Final_Project.c Final_Project.c final_project.c final_project.c final_project.c final_project.c final_project.c final_project.c Line Suppression St 118 108 109 112 113 116
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
