Originally Posted by
cooper1200
I don't really understand dynamically assigning memory or what the stack is or where it comes from and even if that is where dynamically assigned memory comes from. because of this and the fact i still trip up on arrays and pointers im afraid to try anything in case i start writing somewhere important and over write the address of my hd or something equally nasty.
coop
You can't write to HDD unless your using system functions to declare where you want to write, in particular driver interface functions since they're what actually write to the HDD if at all (entirely possible to not write at all when running software), but simply put the guys before me have a point about keeping the initialization code of carda out of deal(), in particular I suggest using calloc() to create your card list instead of [52] and put the result of that in a variable called possible_cards, then seperatly reference those cards with a pointer list (also initialized with calloc()), example of what I mean:
Code:
card_t InitCardList(size_t num) {
return calloc( num, sizeof(card_t) );
}
void FreeCardList( card_t *cards ) {
if ( !cards ) return;
free(cards);
}
...
int main(...) {
size_t num = 52, pnum = 4, *phand = NULL;
card_t *cards = InitCardList(num);
card_t ***players = InitPlayerList( pnum, &phand, cards, num );
do {
deal( players, pnum, phand );
}
while ( play( players, pnum, phand ) > 1 );
FreePlayerList( players, pnum, phand );
FreeCardList( cards );
return 0;
}