I had a issue with running a c-program. I am using Turbo C++ compiler but when I write a code and compile there is no problem with compiling. But when I run program is doesn't display any output.
This is the code:
#include<stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}
let me solve your problem,buddy.
Problem: program doesn't display the output.
Reason:
Program execution takes milleseconds to display the output & turbo c++ compilor has not control over it. So, it's the responsibility of coder to control the execution to display the output.
Solutions:
1.using getch(); //it is predefined function of <conio.h>
2.using getchar(); //it is predefined function of <stdio.h>
Using getch();
Code:
#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;
}
USING getchar();
Code:
#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;
}