c - Visual Studio 2012 C 访问代码错误

标签 c visual-studio-2012 compiler-errors scanf

我正在用 C 编写一个小的家庭作业程序,我遇到了一个非常不寻常的问题。我使用 Visual Studio 2012 在 C 中对此进行了编码。程序编译没有错误,并且它还在 cmd 中运行,直到它崩溃并出现异常的某个阶段。请忽略程序的逻辑,我删掉了一些部分以专注于错误本身。我真的很感激这方面的帮助。谢谢!

程序如下:

#include <stdio.h>
#include <math.h>

int main( void )
{
    int menuinput;
    int austinHour, austinMinute;
    int irishHour, irishMinute;
        printf("Insert a Number from 1-11 to select menu option: ");
        scanf_s("%d",&menuinput);
        switch(menuinput)
        {
            case 1:
            { 
                irishHour=0;
                irishMinute=0;
                austinHour=0;
                austinMinute =0; 
                printf("Enter Austin time: ");
                scanf_s("%d %d",austinHour,austinMinute);
                irishHour = (austinHour + 61);
                printf("%d %d",irishHour, austinMinute);
            }
                }

当我尝试运行程序时出现以下错误:

First-chance exception at 0x62ACD745 (msvcr110d.dll) in Lab2.exe: 0xC0000005: Access violation writing location 0x00000000.

If there is a handler for this exception, the program may be safely continued.

最佳答案

你打错了,你没有在scanf中传递参数地址:

 printf("Enter Austin time: ");
 scanf_s("%d %d",&austinHour,&austinMinute);
                 ^^          ^^

我说这是一个打字错误,因为您第一次使用 scanf 时就正确地做到了:

scanf_s("%d",&menuinput);

关于c - Visual Studio 2012 C 访问代码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14557183/

相关文章:

c - C语言中如何在一个输入中获取多个字符

c - 从主机 linux 系统读取应用程序范围内的环境变量

c# - 无法执行插入、删除或更新?

c++ - 在 c 文件中使用 C++ 类

c - Rust如何将结构转移回C?

asp.net - 从带空格的文件夹进行 Web 部署

wpf - 为什么发布无法发布System.Net.Http.dll?

java - “找不到符号”或“无法解析符号”错误是什么意思?

java - 在 netscape.javascript.JSObject 中找不到 getWindow(Applet)

java - 涉及转换的奇怪编译错误