c - 'For' 中的 'If' 使游戏崩溃 - C 语言

标签 c

这是一段代码:(whyerror1.exe)

#include <stdio.h>
#include <stdlib.h>
int i, n, health=100;
int main(void)
{
    for (i=0; i<1; i++)
    {
        printf("health: %d\n",health);
        printf("There is meat on the ground.\n");
        printf("Will you eat it?\n");
        printf("1: yes  2: no\n"); 
        scanf("%d", n);
        if(n==1) {
                      system("cls");
                      printf("Ate it. \n");
                      printf("There is no people, so it is safe to eat. \n");
                      printf("Health is increased.\n");
                      system("pause>nul");
                      system("cls");
                      }
        else if(n==2) {
                      system("cls");
                      printf("Didn't ate it. \n");
                      printf("More hunger, less health. \n");
                      system("pause>nul");
                      system("cls");
                      }
        else {
                     printf("select between 1 and 2. \n");
                     system("pause>nul");
                     system("cls");
                     i=-1;
        }
    }
}

结果:whyerror1.exe 停止工作。 为什么会这样? 我已经尝试选择其他号码。我试过任何数字! 请帮忙!

最佳答案

scanf("%d", n);

应该是:

scanf("%d", &n);

关于c - 'For' 中的 'If' 使游戏崩溃 - C 语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20149286/

相关文章:

c - 如何获取目录中的目录数?

c - 错误地传递参数? C题

c - fork() 函数永远不会返回 0

c - 如果输入错误,则双重询问输入

c - 如何检查套接字的接收或发送点是否已关闭

c - 搜索链表时输出错误

c - 使用 windows.h 读取 c 中的行

objective-c - 如何在 OSX 中以编程方式获取 GPU 温度?

c - 我只是不确定我哪里出错了。编写一个程序来打印出 c 中的质因数分解并练习与之相关的链接

c - 使用 C 编程使用 POPEN 将值存储到字符串中