gpt4 book ai didi

c - 添加了 goto 语句;现在我收到 EXC_BAD_ACCESS 错误

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

我听说这些也很危险。我用了一个来简单地进行“有效输入”检查。这是代码

char info_check = 'q';
while (info_check != 'y') {
Quadratic* eqn=newquadratic();
printf("\nThe coefficients entered for '%s' are a=%g, b=%g and c=%g.\n", eqn->name_or_descrpt, eqn->a, eqn->b, eqn->c);
printf("\nIs this information correct? (y/n): ");
get_valid_option:
scanf("%c", info_check);
if (info_check != 'n' || info_check != 'y') {
printf("\n\nInvalid choice! Please input either y or n: ");
goto get_valid_option;
}
}

在我认为无伤大雅的 goto 语句添加之前,代码运行良好。奇怪的是,错误发生在 goto 标记之前,并且没有打印第二个 printf。怎么回事?

最佳答案

您在 scanf 中的 info_check 之前错过了 & 运算符。

 scanf(" %c", &info_check);

并且还在 %c 说明符之前放置一个空格来吃掉之前 scanf 遗留下来的换行符 (\n)。

关于c - 添加了 goto 语句;现在我收到 EXC_BAD_ACCESS 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20032673/

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