c - programname.exe 在 Windows 10 中已停止工作对话框

标签 c eclipse windows gcc windows-10

我正在使用 Windows 10,TDM-GCC 和 Eclipse NEON 开发工具,点击运行按钮后无法执行程序,我也没有看到它在编译后抛出的任何错误消息。它显示了未执行程序的 Windows 10 对话框,其中显示“出现问题导致程序停止正常工作。Windows 将关闭该程序并在有可用解决方案时通知您。”

我正在尝试运行的程序-

#include<stdio.h>

 int first;
 int second;
 int *firstreference;
 int *secondreference;

 void calledbyvalue(int input);
 void calledbyreference(int *input);

  void calledbyvalue(int input){

   //disabling the buffer
   setbuf(stdout, NULL);

   printf("Enter the first value - ");
   scanf("%d", &input);
   printf("Value entered for first is - %d", input);
   printf("Entered input is - %d",input);

  }

  void calledbyreference(int *inputreference){

    //disabling the buffer
    setbuf(stdout, NULL);

    printf("Enter the second value - ");
    scanf("%d", &inputreference);
    printf("Value entered for second is - %d", inputreference);
    printf("Entered input reference value is - %d",&inputreference);

   }

   void main(){

   *firstreference = &first;
   *secondreference = &second;

  //Calling user defined functions here .... 
  calledbyvalue(first);
  calledbyreference(firstreference);

 calledbyvalue(second);
 calledbyreference(secondreference);

}

最佳答案

部分

*firstreference = &first;
*secondreference = &second;

通过取消引用 NULL 来调用未定义的行为,这是没有显式初始化的静态指针变量的初始值。不要那样做。要将指针分配给 firstsecond,请使用

firstreference = &first;
secondreference = &second;

也是部分

scanf("%d", &inputreference);
printf("Value entered for second is - %d", inputreference);
printf("Entered input reference value is - %d",&inputreference);

通过将指向具有错误类型的对象的指针传递给 scanf() 并将具有错误类型的数据传递给 printf() 来调用未定义的行为。你想要的可能是这样的:

scanf("%d", inputreference);
printf("Value entered for second is - %d", *inputreference);
printf("Entered input reference value is - %d",*inputreference);

另外需要注意的是,您应该在托管环境中使用标准的 int main(void) 而不是 void main(),这在 C89 中是非法的并且是实现定义的在 C99 或更高版本中,除非您有特殊原因使用非标准签名。

关于c - programname.exe 在 Windows 10 中已停止工作对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38989470/

相关文章:

c - 运行时检查失败#2

C : getchar() and putchar()

c - 在堆栈中间查找元素

java - 我如何到达 AST 表达式的底部

android - 在 Eclipse 中使用数组向画廊图像添加声音

java - 由于 appcompat v7,R.java 没有生成?

python - 如何在windows下自动运行python脚本?

c - 使用 C 返回数组

c# - 如何以编程方式发现系统上映射的网络驱动器及其服务器名称?

windows - 如何在批处理文件中运行 wmic 命令