I have a struct:
and another:Code:typedef struct PLAYER { char *name; int cash; int AI; card hand[1]; } player;
within this section of code sumthing odd happens:Code:typedef struct CARD { short int index; Suit suit; Value value; char name[18]; } card;
newDeck function. in Deck.c:Code:extern player Player[]; initPlayers(Name); printf( "CashB = %d\n", Player[0].cash ); /* Player[0].cash = 2500 */ newDeck(Deck); printf( "CashC = %d\n", Player[0].cash ); /* Player[0].cash = 3 */
newCard function. in Card.c:Code:int newDeck(card * Deck) { int i; extern player Player[]; printf( "CashBA = %d\n", Player[0].cash ); /* Player[0].cash = 2500 */ for( i=0; i<52; i++) { newCard(&Deck[i], i); } printf( "CashBB = %d\n", Player[0].cash ); /* Player[0].cash = 3 */ return 0; }
Does anyone know why Player[0].cash could change, when no Player variables are even mentioned or used within this function newCard (i only used 'extern player Player;' to check the value of Player[0].cash)Code:int newCard(card *Card, int index) { extern player Player[]; printf( "CashBAA = %d\n", Player[0].cash ); /* Player[0].cash = 2500 */ Card->index = index; Card->value = (index%13); Card->suit = (index/13); cardName(Card); printf( "CashBAB = %d\n", Player[0].cash ); /* if(index == 51)Player[0].cash = 3; else Player[0].cash = 3;*/ }
cardName(Card); also doesnt reference and Player variables.



LinkBack URL
About LinkBacks


