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

kuhbmx9i  于 2024-01-08  发布在  其他
关注(0)|答案(1)|浏览(250)
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int leNumeroInteiro();
  4. void leDadosRetangulo(int *comp, int *larg);
  5. void areaRetangulo(int comp, int larg);
  6. void limparBufferStdin();
  7. int main() {
  8. int comp, larg;
  9. leDadosRetangulo(&comp, &larg);
  10. areaRetangulo(comp, larg);
  11. return 0;
  12. }
  13. void limparBufferStdin() {
  14. int c;
  15. while ((c = getchar()) != '\n' && c != EOF);
  16. }
  17. int leNumeroInteiro() {
  18. int num;
  19. do {
  20. scanf("%d", &num);
  21. limparBufferStdin();
  22. } while (!(num > 0));
  23. return num;
  24. }
  25. void leDadosRetangulo(int *comp, int *larg) {
  26. printf("=====================\n");
  27. printf("\nIntroduza o comprimento do retangulo: ");
  28. *comp = leNumeroInteiro();
  29. printf("\nIntroduza a largura do retangulo: ");
  30. *larg = leNumeroInteiro();
  31. printf("=====================\n");
  32. }
  33. void areaRetangulo(int comp, int larg) {
  34. float area;
  35. area = (float)comp * larg;
  36. printf("=====================\n");
  37. printf("A area desse retangulo e: %.2f\n", area);
  38. }

字符串
它会一直运行代码,直到我取消。(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很多次,我看到了很多教程。我越来越绝望了。

g6ll5ycj

g6ll5ycj1#

你在“终端”中运行程序吗?我怀疑你没有。我运行了你的程序,它对我来说工作得很好。所以我想你只是在IDE的错误部分。

相关问题