S
Simon
I've got a simple and repetitive bit of code for a function in a C
implementation of the card game 31s I'm working on. BTW, I am a bit of
a novice at C; for the past couple of years I was using Visual Basic,
but I wanted portability, so I chose C.
I am developing this in XCode 2 (on Mac OS 10.4.7) as a normal C
command line utility; so this is basically just GCC. This code compiles
fine, without any errors or warnings but when I run it in XCode it
says: "31s has exited due to signal 11 (SIGSEGV)." and in Terminal it
says "Segmentation Fault". Here is the code of most of the function,
and what I'm pretty sure is the faulty bit. I can post all the code up
if needed; it's all in one .c file.
void print_stats() {
int
location_of_player_card_1,location_of_player_card_2,location_of_player_card_3;
int
location_of_CPU1_card_1,location_of_CPU1_card_2,location_of_CPU1_card_3;
int
location_of_CPU2_card_1,location_of_CPU2_card_2,location_of_CPU2_card_3;
int
location_of_middle_card_1,location_of_middle_card_2,location_of_middle_card_3;
int x,y;
while (x<52) {
if (where_are_cards[x] = PLAYER_HAND) {
switch (y) {
case 0:
location_of_player_card_1 = x;
y++;
break;
case 1:
location_of_player_card_2 = x;
y++;
break;
case 2:
location_of_player_card_3 = x;
y++;
break;
}
}
x++;
}
x,y = 0;
while (x<52) {
if (where_are_cards[x] = CPU1_HAND) {
switch (y) {
case 0:
location_of_CPU1_card_1 = x;
y++;
break;
case 1:
location_of_CPU1_card_2 = x;
y++;
break;
case 2:
location_of_CPU1_card_3 = x;
y++;
break;
}
}
x++;
}
x,y = 0;
while (x<52) {
if (where_are_cards[x] = CPU2_HAND) {
switch (y) {
case 0:
location_of_CPU2_card_1 = x;
y++;
break;
case 1:
location_of_CPU2_card_2 = x;
y++;
break;
case 2:
location_of_CPU2_card_3 = x;
y++;
break;
}
}
x++;
}
x,y = 0;
while (x<52) {
if (where_are_cards[x] = MIDDLE) {
switch (y) {
case 0:
location_of_middle_card_1 = x;
y++;
break;
case 1:
location_of_middle_card_2 = x;
y++;
break;
case 2:
location_of_middle_card_3 = x;
y++;
break;
}
}
x++;
}
printf("Table:\n");
printf(" Your hand: ");
print_card(pack[location_of_player_card_1]);
print_card(pack[location_of_player_card_2]);
print_card(pack[location_of_player_card_3]);
}
implementation of the card game 31s I'm working on. BTW, I am a bit of
a novice at C; for the past couple of years I was using Visual Basic,
but I wanted portability, so I chose C.
I am developing this in XCode 2 (on Mac OS 10.4.7) as a normal C
command line utility; so this is basically just GCC. This code compiles
fine, without any errors or warnings but when I run it in XCode it
says: "31s has exited due to signal 11 (SIGSEGV)." and in Terminal it
says "Segmentation Fault". Here is the code of most of the function,
and what I'm pretty sure is the faulty bit. I can post all the code up
if needed; it's all in one .c file.
void print_stats() {
int
location_of_player_card_1,location_of_player_card_2,location_of_player_card_3;
int
location_of_CPU1_card_1,location_of_CPU1_card_2,location_of_CPU1_card_3;
int
location_of_CPU2_card_1,location_of_CPU2_card_2,location_of_CPU2_card_3;
int
location_of_middle_card_1,location_of_middle_card_2,location_of_middle_card_3;
int x,y;
while (x<52) {
if (where_are_cards[x] = PLAYER_HAND) {
switch (y) {
case 0:
location_of_player_card_1 = x;
y++;
break;
case 1:
location_of_player_card_2 = x;
y++;
break;
case 2:
location_of_player_card_3 = x;
y++;
break;
}
}
x++;
}
x,y = 0;
while (x<52) {
if (where_are_cards[x] = CPU1_HAND) {
switch (y) {
case 0:
location_of_CPU1_card_1 = x;
y++;
break;
case 1:
location_of_CPU1_card_2 = x;
y++;
break;
case 2:
location_of_CPU1_card_3 = x;
y++;
break;
}
}
x++;
}
x,y = 0;
while (x<52) {
if (where_are_cards[x] = CPU2_HAND) {
switch (y) {
case 0:
location_of_CPU2_card_1 = x;
y++;
break;
case 1:
location_of_CPU2_card_2 = x;
y++;
break;
case 2:
location_of_CPU2_card_3 = x;
y++;
break;
}
}
x++;
}
x,y = 0;
while (x<52) {
if (where_are_cards[x] = MIDDLE) {
switch (y) {
case 0:
location_of_middle_card_1 = x;
y++;
break;
case 1:
location_of_middle_card_2 = x;
y++;
break;
case 2:
location_of_middle_card_3 = x;
y++;
break;
}
}
x++;
}
printf("Table:\n");
printf(" Your hand: ");
print_card(pack[location_of_player_card_1]);
print_card(pack[location_of_player_card_2]);
print_card(pack[location_of_player_card_3]);
}