Back to Computers & Modding
How to keep window open in c?
V
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)
L
for what reason do you want to keep the window open?
V
(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)
L
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.
V
Like let's take the hello world example. If you just put that in, should it work? My code compilesfine without errors so...dk
L
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.
V
So haw do O keep it open?
M
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();}
V
Ok thank you. I appreciate all the help :)
Showing posts 1–9 of 9 · This discussion is archivedBack to top