Hi,
How can i make that the console, with the output, will not disapear after the program ends in VS 2010 express C++?
i write in c and not in c++, soo i need a function and include path to library.
Thanks
Hi,
How can i make that the console, with the output, will not disapear after the program ends in VS 2010 express C++?
i write in c and not in c++, soo i need a function and include path to library.
Thanks
You can simply poll for input. This performs a block so that the function only returns when the user gives more input - usually enter. If you're on Windows you can also use system("PAUSE").
You have a few options:
getchar()
before you return from main.system("pause")
before you return from mainint waitforenter(void) {
int ch;
puts("press ENTER (maybe twice)");
/* get rid of a (possibly) pre existing '\n' */
do {
ch = getchar();
} while ((ch != EOF) && (ch != '\n'));
/* and again */
if (ch != EOF) do ch = getchar(); while ((ch != EOF) && (ch != '\n'));
return ch;
}
And then call waitforenter()
right before the end of your main()
function.
Pressing Ctrl+F5 ("Build -> Start Without Debugging") will run the application and automatically wait for a keypress before closing the console. However, as the name says, you do not have a debugger attached then.