小编Unk*_*yer的帖子

如何在 Git bash 中运行 C 程序?

我在 Windows 上,使用 git bash 来运行我的 c 程序。

我使用 gcc 来编译代码。当我只做一个简单的事情时printf("hello, world");,它可以工作,但是当我尝试创建一个简单的程序来添加两个数字时,它什么也不做。

它可以编译,gcc -o sum sum.c但是当我使用它运行./sum它时,它什么也不做,但是当我在命令提示符中运行它时,它运行正常。

#include <stdio.h>

int main(void) {
    int n1, n2;

    printf("Enter a number: ");
    scanf("%d", &n1);
    printf("Enter another number: ");
    scanf("%d", &n2);

    int sum = n1 + n2;

    printf("Sum: %d\n", sum);
}
Run Code Online (Sandbox Code Playgroud)

我尝试在 git bash 中输入值并得到与 cmd 相比的输出

c git-bash

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

c ×1

git-bash ×1