I'm doing a programming exercise from the book "Programming Challenges" where I'm trying to write a program that simulates the card game "War".
I'm getting the following errors when I try to compile my code:
Code:
cards.c: In function ‘shuffle’:
cards.c:54:39: error: expected expression before ‘Card’
cards.c:86:20: error: ‘Card’ has no member named ‘next’
cards.c:87:26: error: ‘Card’ has no member named ‘next’
cards.c:90:9: error: ‘Deck’ has no member named ‘top’
cards.c:91:9: error: ‘Deck’ has no member named ‘bottom’
...
cards.c: In function ‘new_standard_deck’:
cards.c:36:17: error: ‘Card’ has no member named ‘next’
cards.c:37:17: error: ‘Card’ has no member named ‘suit’
cards.c:38:17: error: ‘Card’ has no member named ‘rank’
...
(lots more of these)
I get this error every time I try to access the any of the members of either the Card or Deck structs, and I can't figure out why, because I have defined them as follows:
Code:
typedef struct Card {
struct Card * next = NULL;
unsigned short int rank = 0;
unsigned short int suit = 0;
} Card;
typedef struct Deck {
Card * top = NULL;
Card * bottom = NULL;
} Deck;
I don't think it makes a difference, but I am compiling it with the following gcc command:
Code:
gcc -Wall -std=c99 war.c cards.c -o war
I'm sure there are plenty of other errors in my code, but for now, I'd just like someone to help me out with this one and let me try to figure out the rest on my own.
I've attached the full source files to this post, but it would only let me attach 3 of 4, so I posted the last header (war.h) to the bottom.
Thanks,
jrtayloriv
---------
Code:
//war.h
#ifndef WAR
#define WAR
#include <stdio.h>
#include "cards.h"
int war();
void init_war_decks(Deck * a, Deck * b);
int play_round(Deck * a, Deck * b);
double avg_game_length(int * turns_sample, int sample_size);
#endif