我在运行 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/