gpt4 book ai didi

c - 在c代码中出现错误

转载 作者:太空宇宙 更新时间:2023-11-04 01:13:57 25 4
gpt4 key购买 nike

我收到以下错误消息:

Program received signal SIGSEGV, Segmentation fault. 0x08048ff3 in key_deck (key=0x0) at c1.c:210 210 for (; *key != '\0'; key++) { (gdb)

这是我的代码:

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;
}

所以错误出在 for 循环的行中,其中 key 正在迭代 - 我在这里做错了什么?在此先感谢您的帮助。

最佳答案

您正在使用 NULL 指针作为参数调用您的函数。您可以在收到的错误消息中看到这一点:

... in key_deck (key=0x0) ...

关于c - 在c代码中出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5779355/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com