【问题标题】:Program is not working. Compiles and runs ok, but if I enter a number, it just crashes程序不工作。编译并运行正常,但是如果我输入一个数字,它就会崩溃
【发布时间】:2016-12-02 23:13:25
【问题描述】:

我已经隔离了给我问题的代码部分:

int i;

printf("Hit [1] to begin");
scanf("%d", i);

if (i == 1)
    printf("The program will now execute");
else
    printf("Error.")

每当我尝试编译程序时,我都没有收到任何警告或错误,但是当我在 CMD 中运行它并输入 1 来运行我的程序时,会弹出一个窗口说程序停止工作并自动退出任务.

任何帮助将不胜感激。

【问题讨论】:

标签: c


【解决方案1】:

请在尝试清除所有编译器警告之前参考scanf 语法。如果您清除,您可能不会遇到这种情况。

scanf("%d", i); 中的错误

解决方案scanf("%d", &i); 您需要使用& 为变量i 提供地址。

这是因为地址问题而崩溃的原因。

【讨论】:

  • 我很快注意到编译器警告会立即发现这一点。
  • 非常感谢!你救了我!
  • @user3477984 社区随时为您提供帮助。
猜你喜欢
  • 2022-11-27
  • 1970-01-01
  • 1970-01-01
  • 2011-06-26
  • 1970-01-01
  • 1970-01-01
  • 2015-03-31
  • 1970-01-01
  • 2017-07-12
相关资源
最近更新 更多