Hello - I am working on a console program that takes a text file as input and writes to another text file. I've been using the console window to display error messages, which works fine when I run the program from within the IDE. But when I run it by double-clicking the .exe file the console window closes instead of waiting with "Press any key to continue..." Is there a way to get the standalone program to retain this behavior? Sorry if this is a stupid question. I did try searching but didn't find an answer.
Well, you have simply been looking for something that doesn't exist (to be able to be retained)...
The "Press any key to continue..." is printed/executed by the IDE, on return of the finished console program.
In order to "retain" this feature in your console program, you have to explicitly program it to print this text and wait for a key response...
And in contrast to what jj2007 suggested, use _getch (), it does exactly what you need...
#include "stdio.h"
#include "conio.h"
int main (void)
{
puts ("Hit any key to continue...");
_getch ();
return (0);
}
Ralf