Back to Computers & Modding

How to keep window open in c?

OP
#1
Hello
I have tried to use system pause in my c program but it will only display press any key to continue. Any other ideas? (Dev cpp)
for what reason do you want to keep the window open?
OP
(The command prompt) because it opens the closes with regular code. And when I use cmd prompt it does not display anything (even though a printf is first)
if its not displaying anything when you run it via command prompt then theres something wrong with your code. What you probably should do is when it finishes, output a message along the lines of 'Press Q to quit' and then loop waiting for the user to press q.
OP
Like let's take the hello world example. If you just put that in, should it work? My code compilesfine without errors so...dk
It's a while since I've used C/C++, but

int main(int argc, char* argv[])
{
	printf("Hello World!\n");
	return 0;
}
will output 'Hello World' and terminate. A console program will always terminate on completion unless programmed otherwise.
OP
So haw do O keep it open?
Put some "getchar"s in there, otherwise the program will end without waiting for user input.#include <stdio.h>
int main()
{printf("Hello vivo");
getchar();}
OP
Ok thank you. I appreciate all the help :)
Showing posts 1–9 of 9 · This discussion is archivedBack to top