- #1
jjc
- 21
- 0
I am writing a program in C (vanilla, non-C++/C#) and I am having trouble figuring out why my initialization of my array of structures isn't working. I have tried a number of things without any luck. I still get a compiler error: "conflicting types for 'cardInfo' "
I am writing a simple implementation of a card game (Dominion) and each card has different costs, effects, etc. So I was going to make a struct, plop a bunch into an array (we only need to implement 27 cards, already specified) so that I could access various bits of info about them more easily (I need the cost in the Buying phase, the Coins and Actions in another phase, etc).
There is an ENUM earlier in the program that defines the names 'curse', 'estate', 'treasure_map' and others. So I am using those enums as indexes (as well as defining the array size). So when defining the array elements (the cardDef structures) I am trying to set the 0-index element as the Curse card ('curse' enum is 0), the 1-index as "Estate" ('estate' enum is 1).
Any pointers (haha - no C pointers please) and help would be appreciated. I imagine that it is something simple, but the various references and tutorials that I have found on this seem to point to the method that I use in the first line. No love from GCC, though. And it's late, and I am cross-eyed from staring at this. :)
Thanks!
Justin
I am writing a simple implementation of a card game (Dominion) and each card has different costs, effects, etc. So I was going to make a struct, plop a bunch into an array (we only need to implement 27 cards, already specified) so that I could access various bits of info about them more easily (I need the cost in the Buying phase, the Coins and Actions in another phase, etc).
There is an ENUM earlier in the program that defines the names 'curse', 'estate', 'treasure_map' and others. So I am using those enums as indexes (as well as defining the array size). So when defining the array elements (the cardDef structures) I am trying to set the 0-index element as the Curse card ('curse' enum is 0), the 1-index as "Estate" ('estate' enum is 1).
Code:
struct cardDef {
char name[MAX_NAME];
enum CARDTYPES card_type;
int card_cost;
int victory_points;
int addBuyCcoins;
int addActions;
int addCards;
};
struct cardDef cardInfo[treasure_map + 1]; /*my attempted array declaration */
/*Trying to initialize the elements of the array here. This first line is where I get the
compiler error; the other lines are examples of other styles that still got the same error. */
struct cardDef cardInfo[curse] = {"Curse", CURSE, 0, -1, 0, 0, 0};
cardDef cardInfo[duchy] = {"Duchy", VICTORY, 5, 3, 0, 0, 0};
cardInfo[estate] = {"Estate", VICTORY, 2, 1, 0, 0, 0};
Any pointers (haha - no C pointers please) and help would be appreciated. I imagine that it is something simple, but the various references and tutorials that I have found on this seem to point to the method that I use in the first line. No love from GCC, though. And it's late, and I am cross-eyed from staring at this. :)
Thanks!
Justin