help with a c program(newbie question)
I am doing a c program, console app. but everytime I run the program, the "dos" window appears and then dissapears before I can see the out put. Is there some sort of delay timer I can place in my code, or a line that states to wait for user intervention before closing.
Thanks in advance.
The only time the world beats a path on my door, I happen to be in the bathroom.
Put a call to getch() in at the end of your main function, eg:
printf("Press a key to end...\r\n");
getch();
That should leave the DOS window open until the user presses a key or manually closes it by clicking the [x] on the DOS window.
printf("Press a key to end...\r\n");
getch();
That should leave the DOS window open until the user presses a key or manually closes it by clicking the [x] on the DOS window.
December 21, 2001 02:58 PM
If you are using Visual C++ push CTRL f5 instead of just f5 when running your app.
I tried the getch() command, but it is still doing the same thing. I am using Dev-C++ would that have anything to do with it?
The only time the world beats a path on my door, I happen to be in the bathroom.
Dev-C++ is simply an IDE. The compiler behind it is GCC. The library definitions that are included with it (MinGW32) don''t include getch since it isn''t a standard function in the first place. You can use an alternative that''s equally effective through either: Running the program from a console in the first place (what I''d do) or putting a call to getchar at the end of the program (basically, it waits until you hit enter).
[Resist Windows XP''s Invasive Production Activation Technology!]
[Resist Windows XP''s Invasive Production Activation Technology!]
couldnt he just use kbhit()?
"You can observe a lot just by watching."- Yogi Berra
"You can observe a lot just by watching."- Yogi Berra
-----------------------------When men speak of the future, the Gods laugh.An apology for the devil: it must be remembered that we have heard one side of the case. God has written all the books.Samuel Butler (1835 - 1902)
You could also try system("PAUSE");
if you use this method, include stdlib.h
if you use this method, include stdlib.h
quote:
Original post by clrscr
couldnt he just use kbhit()?
That isn''t any more standard than "getch" is (no, I don''t think it is supported by the GCC+MinGW32 setup either).
quote:
Original post by m0rte
You could also try system("PAUSE");
While, yes, he could, that would be bad practice. Relying on the system''s command line parser isn''t a good idea. In general, it''s a bad habit to pick up

[Resist Windows XP''s Invasive Production Activation Technology!]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement