I am getting the following error message:
Program received signal SIGSEGV, Segmentation fault. 0x08048ff3 in key_deck (key=0x0) at c1.c:210 210 for (; *key != '\0'; key++) { (gdb)
This is my code:
static void key_deck(
char *key
)
{
int i, kval, *tmp;
state.deck = state.deck1 + 3;
state.spare = state.deck2 + 3;
for (i = 0; i < 52; i++) {
state.deck[i] = i+1;
}
state.deck[state.a = 52] = 53;
state.deck[state.b = 53] = 53;
for (; *key != '\0'; key++) {
if ( *key >= 'A' && *key <= 'Z' ) {
cycle_deck(0); /* Special value '0' is only useful here... */
/* And now perform a second count cut based on the key letter */
kval = *key - 'A' + 1;
for (i = 0; i < 53; i++)
state.spare[i] = state.deck[(i + kval) % 53];
state.spare[53] = state.deck[53];
if (state.a != 53)
state.a = (state.a + 53 - kval) % 53;
if (state.b != 53)
state.b = (state.b + 53 - kval) % 53;
tmp = state.deck;
state.deck = state.spare;
state.spare = tmp;
if (verbose) {
print_deck();
printf(" after %c\n", *key);
}
}
}
/* These are touched by the keying: fix them. */
lastout = 100; cocount = 0;
}
So the error is in the line of the for loop where key is iterating -- what am I doing wrong here? Thanks in advance for any help.