Back to Computers & Modding

How to keep window open in c?

vivoOP
#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)
Loonylion
#2
for what reason do you want to keep the window open?
vivoOP
#3
(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)
Loonylion
#4
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.
vivoOP
#5
Like let's take the hello world example. If you just put that in, should it work? My code compilesfine without errors so...dk
Loonylion
#6
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.
vivoOP
#7
So haw do O keep it open?
markswan
#8
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();}
vivoOP
#9
Ok thank you. I appreciate all the help :)
Showing posts 1–9 of 9 · This discussion is archivedBack to top