c - 运行程序无输出

标签 c turbo-c

我在运行 C 程序时遇到了问题。我正在使用 Turbo C++ 编译器,但是当我编写代码并编译时,编译没有问题。但是当我运行程序时不显示任何输出。

这是代码:

#include<stdio.h>
int main()
{
    printf("Hello World\n");
    return 0;
}

最佳答案

让我来解决你的问题,伙计。

问题:程序不显示输出。

原因:

程序执行需要几毫秒才能显示输出,turbo c++ 编译器无法控制它。因此,编码人员有责任控制执行以显示输出。

解决方案:

1.使用 getch(); //it is predefined function of <conio.h>

2.使用 getchar(); //it is predefined function of <stdio.h>

使用 getch();

代码:

 #include <stdio.h>
    #include <conio.h>
    
    int main()
    {
      printf("Hello world\n");
      getch();                  //it can be used to hold program execution,it wait until the user enters a character.
      return 0;
    } 

使用 getchar();

代码:

    #include <stdio.h>
    int main()
    {
      printf("Hello world\n");
      getchar();                  //getchar() means get a character from user,if user press any key + enter then getchar() executes.
      return 0;
    } 


   
 

关于c - 运行程序无输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44024039/

相关文章:

c - scanf() 将换行符保留在缓冲区中

Conio.o 在 Dev C 中不可用 - C

谁能告诉我c中的列表文件和映射文件是什么?

c++ - Borland C++ 不是 C++?

c - Scanf 将错误类型的变量寻址到数组

c++ - malloc 或我的错误?

c - 如何在不使用 <math.h> 和 printf (".n%f"的情况下将 c 中的浮点变量舍入到 2/3/4....n 位精度

c - 生成文件别名

c - Turbo C 中的 SHA256 算法无法编译

c - 未指定模块定义文件