when i press Ctrl+F9 , the output screen comes and goes without stopping for a while.
Please note that i have included "#include<stdio.h>" and i am using "getchar()" function do stop the screen.
A previous call to scanf() of getchar() is probably leaving characters in the stream. The getchar() you are using to stop the screen only works if the stream is completely empty. You can fix that by adding a loop that reads and throws away characters until a line break is found. Here is a utility function that can do what you want:
void PauseForUser(int promptUser, int clearStream)
{
if (clearStream)
{
int c;
while ((c = getchar()) != '\n' && c != EOF)
{
/* all work in condition */
}
clearerr(stdin);
}
if (promptUser) fputs("Press [Enter] to continue", stdout);
getchar();
}
In your code it might be called as
PauseForUser(1, 1); .
may I know the hazards or any side-effect of using getch() it in TurboC.
Turbo C is becoming increasingly less compatible with the rest of the world as it ages, and using getch() is one way to lock your code into a specific compiler. The graphics.h header is another, worse way.
Using getchar() we have to press the enter key but using getch() we can just press any key then why getchar() instead of getch().
IMO that is not a deal breaker for getchar(), and it is not enough of a benefit to add an extra portability concern. Personally, I think this is a trivial thing to argue over, kind of like void main(). It is well known, easy to spot, easy to change, and not likely to cause horrible problems. But because of these things that are well known, easy to spot, and easy to change, they are also easy for coding snobs to act all elitist about.