1

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.

5
  • What is the exact error message that you are getting? Commented Apr 25, 2011 at 14:31
  • 3
    Three things - first, give the extra error in the question. "An error" is not useful. Second, give enough code that we see the variable declerations. Knowing the types is important. Third, it is essential you provide an explanation of what you're trying to achieve. Commented Apr 25, 2011 at 14:32
  • error is: Program received signal SIGSEGV, Segmentation fault. 0x08048ff3 in key_deck (key=0x0) at c1.c:210 210 for (; *key != '\0'; key++) { (gdb) Commented Apr 25, 2011 at 14:32
  • Why did you post the exact same question again, rather than editing that one? Commented Apr 25, 2011 at 14:47
  • i didnt know whether i can edit that one. sorry for that am new her in stackoverflow Commented Apr 25, 2011 at 14:53

2 Answers 2

4

You are calling your function with a NULL pointer as a parameter. You can see this in the error message you got:

... in key_deck (key=0x0) ...
Sign up to request clarification or add additional context in comments.

1 Comment

It means that wherever you are calling the key_deck function, you need to pass in a valid string.
1

In your error message, you can see that you are passing NULL to the function

key_deck(key=0x0)

The error is actually in the caller.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.