Hi.
I am getting a Seg fault and I don't know why.
Basically, in blackjack, I have a hand of cards and I am trying to sum up the hand:
Above is just the necessary code, well hopefully. Compiles ok, I go to run it and receive a Seg fault. Any idea? I know I'm trying to access something which doesn't belong to me, but I don't know what.Code:struct card_t { unsigned short int card; /* Ace-King (1-13) */ unsigned short int suit; /* Clubs,Diamonds,Hearts,Spades (1-4) */ }; int main(void) { .... printf("mycards score = %d\ncompscards score = %d\n", sum_up_hand( mycards ), sum_up_hand( compscards ) ); ...... } unsigned short int sum_up_hand( struct card_t *hand ) { int i = 0; unsigned short int total = 0; while( (hand + i) != NULL ) { total += value_of_card( (hand + i)->card ); i++; } return total; } unsigned short int value_of_card( unsigned short int n ) { int i, value = 0; for(i = 0; i < 10; i++) { /* card ace corresponds to i=0, card 2 corresponds to i=1, and so on until i=9*/ value = ( n == i ) ? i + 1 : 0; } switch( n ) { case 10: //jack value = 10; break; case 11: // queen value = 10; break; case 12: //king value = 10; break; } return value; }



LinkBack URL
About LinkBacks




. But the called function won't know.