i cannot c the output on the scrren and i can't input some values.pls..give me a solution.thanks %26amp; regards.
When i compile c pgms using turbo c,its compiles well.but when i tried to run,it flashes for a sec %26amp; off.why?
Hi, this is just as a guess but it seems that the program is starting up in a DOS box, exiting immediately and shutting down the DOS Box. You need to put a pause in there when the program is completed. The best way to do this is by adding in a call to getch() before the program exits. getch() will read a single character directly from the keyboard, without echoing it to the screen so its ideal for adding a pause at the end of your program.
For example compile and run the following 2 programs. One is with getch() and the other without and see the difference.
// Program 1 Without getch()
#include %26lt;stdio.h%26gt;
#include %26lt;conio.h%26gt;
void main(void)
{
printf("Hello World without a getch()\n");
// This line will not be seen as the DOS box closes
// immediately
}
// Program 2 With getch()
#include %26lt;stdio.h%26gt;
#include %26lt;conio.h%26gt;
void main(void)
{
printf("Hello World with a getch()\n");
// This line will be seen as the DOS box stays open until
// the user presses a key
// wait for user to press a key
getch();
}
Hope that helps. If you are trying to input some values you need to have a closer look how.
Reply:It is hard to answer exactly without seeing your actual code. But I think that You have the problem to see output on the screen. When you run your program, It automatically exits from DOS screen after running the program, so you can not see any output. To see the output , You must write some line of code to pause the screen for some time. The Best way to do this is to cause the program to take some character input from the keyboard. This will causes the screen to be paused until user hits some key. Then, It will return and exit. The library function for taking a single character from the keyboard is getch(), getchar(), getche(). These all are declared in %26lt;conio.h%26gt;, which you should include on top of your file. The best way is to use getch(), because, this function is character buffered. It means that as soon as you hit some key, it will return.
As next part of your question, I think that you have problem with flushing your screen. Whatever input functions you have used, Try putting the fflush(stdin); line just before the line for taking input from keyboard. This function will flush the buffer where the input taken from the keyboard is temporarily stored before passing it to the program variable.
I hope this will solve your problem. If not solved, reply me with some lines of code where you have used input/output functions.
Best of luck
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment