c - 简单的c程序不打印输出

标签 c console

<分区>

我有一个简单的c程序

#include <stdio.h>

int add(int, int);
int add (int a, int b) {
   return a+b;
}

int main(void) {
  int a, b, c;

  printf("Enter the 1st number ");
  scanf("%d",&a);
  printf("Enter the 2nd number ");
  scanf("%d",&b);
  c = add(a, b);
  printf("The value is %d ", c);
  return (0);
}

我正在用 cc main.c 编译程序 当我使用 ./a.out 运行程序时
我在控制台中没有得到任何输出。

最佳答案

出于性能原因,输出被缓冲。替换

printf("The value is %d ", c); 

printf("The value is %d\n", c);

或使用 fflush(stdout);

参见 Why does printf not flush after the call unless a newline is in the format string?

关于c - 简单的c程序不打印输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31904797/

相关文章:

Java如何启动CMD并与其保持连接以进行用户交互?

c - 我应该对网络命令使用#defines 还是枚举?

c - 随机访问C中函数的不定数量的参数

c++ - 英特尔 PIN 例程地址检索 : Linux vs. Windows

node.js - 用于控制台彩色输出的 Node 模板引擎

intellij-idea - 如何将数据记录到 Flutter 控制台?

填充数组时崩溃

c - POSIX/C : chdir() not changing the directory with spaces?

c# - 控制台中的异步无效方法不想触发

javascript - Chrome DevTools 中的 Handled 过滤器有什么用?