我的C程序一直运行,没有出现任何输出

问题描述 投票:0回答:1
#include <stdio.h>
#include <stdlib.h>

int leNumeroInteiro();
void leDadosRetangulo(int *comp, int *larg);
void areaRetangulo(int comp, int larg);
void limparBufferStdin();

int main() {
    int comp, larg;
    leDadosRetangulo(&comp, &larg);
    areaRetangulo(comp, larg);
    return 0;
}

void limparBufferStdin() {
    int c;
    while ((c = getchar()) != '\n' && c != EOF);
}

int leNumeroInteiro() {
    int num;
    do {
        scanf("%d", &num);
        limparBufferStdin();
        
    } while (!(num > 0));

    return num;
}

void leDadosRetangulo(int *comp, int *larg) {
    printf("=====================\n");
    printf("\nIntroduza o comprimento do retangulo: ");
    *comp = leNumeroInteiro(); 
    printf("\nIntroduza a largura do retangulo: ");
    *larg = leNumeroInteiro(); 
    printf("=====================\n");
}

void areaRetangulo(int comp, int larg) {
    float area;
    area = (float)comp * larg;
    printf("=====================\n");
    printf("A area desse retangulo e: %.2f\n", area);
}

它会一直运行代码,直到我取消为止。(https://i.stack.imgur.com/HoXv3.png)

我确认我已正确安装了该版本。 (https://i.stack.imgur.com/6swnD.png)

我选择了正确的路径[即使在环境变量中](https://i.stack.imgur.com/P3D3r.png)

当我只用 printf 运行一个简单的代码时,它工作得很好,但是用我的代码它不会出现任何东西。我尝试在 Codeblocks(其他 IDE)中运行它,它运行得很好。我尝试重新安装Mingw很多次,我看了很多教程。我快绝望了

c gcc path console-application mingw
1个回答
0
投票

您是否在“终端”中运行该程序? 我怀疑你不是。我运行了你的程序,它非常适合我。所以我认为您只是处于 IDE 的错误部分。

© www.soinside.com 2019 - 2024. All rights reserved.