简体   繁体   English

简单的C程序未在Eclipse中显示输出

[英]Simple C program not showing output in eclipse

A few days back I installed Eclipse ide and also the CDT plugin therein for C and C++ development. 几天前,我安装了Eclipse ide以及CDT插件,用于C和C ++开发。 Also made the necessary settings. 还进行了必要的设置。 Also tried a simple C program of adding two integers. 还尝试了一个简单的C程序,将两个整数相加。 Surprisingly, no output was shown in the terminal, but when the program was terminated it showed a wrong output of 0 . 令人惊讶的是,终端中未显示任何输出,但是当程序终止时,其显示的输出为0

The program was this: 程序是这样的:

#include <stdio.h>

int main(){
  int a, b;
  printf("Enter an integer: "); scanf("%d", &a);
  printf("Enter another integer: "); scanf("%d", &b);
  printf("Sum = %d", (a+b));
  return 0;
}

This same program showed the correct output when it was ran using the command prompt: 使用命令提示符运行该程序时,它显示正确的输出:

 gcc -g add.c -o add.exe

Have I made any mistake in the code? 我在代码中犯了任何错误吗? Can anyone suggest me what do I need to do to run it in Wclipse? 谁能建议我在Wclipse中运行它需要做什么?

have you build the project in the first place? 您是否首先构建了项目? Go to "Project" tab in main tool bar and click on build project. 转到主工具栏中的“项目”选项卡,然后单击生成项目。 If successful setup up a new run configuration for C under "Run" tab. 如果成功,请在“运行”选项卡下为C设置新的运行配置。 And in the C/C++ application field -> "Search Project" and choose your project's binary from the list. 然后在C / C ++应用程序字段中->“搜索项目”,然后从列表中选择项目的二进制文件。

Now try running your custom run/debug configuration. 现在尝试运行自定义运行/调试配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM