This is a shameful question for me to ask but how do i keep the debug window open... it keeps on closing automatically rather than me closing it manually.

I am using visual studios and it used to work when I just simply click (ctrl + f5). I doesn't work when i am comiling C....

Any ideas why this is happening?

Dani AI

Generated

This is a very common symptom for native console programs: the console window belongs to the running process, so when the process exits the window closes immediately. put it concisely — nothing in Visual Studio keeps a program window open after the program stops — and ’s idea of handling the program’s exit (an explicit “wait” before returning) is the simplest cross-IDE fix.

Quick checklist to diagnose the problem:

  • Confirm the project is a console application (Project -> Properties -> Configuration Properties -> Linker -> System -> SubSystem should be set to Console). If the project was created as a Windows/GUI app there will be no console to show.
  • Run the produced .exe from a Command Prompt in the output folder. If the exe prints and exits there, the IDE is not the issue — the program is finishing immediately.
  • To inspect output during development, either set a breakpoint near the end of main or make the program wait for input before returning.

A small, portable code pattern to add at the end of main will pause the console without relying on system-specific hacks:

#include <stdio.h>

int main(void) {
    /* program work here */
    puts("Press Enter to exit...");
    getchar();   /* portable pause */
    return 0;
}

Notes and common pitfalls: using system("pause") works on Windows but is non-portable and not recommended for production; a disappearing console can also indicate a crash — check the Output and Error windows and run under the debugger to catch exceptions; if problems persist, recreating the project as a Win32/Console project often fixes accidental project-type misconfiguration.

Recommended Answers

All 5 Replies

if you have code::blocks, just open your project and find the main loop. there should be something like an exit case statement where you type something like Return EXIT_SUCCESS. at least in c++.

I see how that works in codeblocks, but how can i get this to work in visual studios (2012)? I don't really seee that in vs...

First: There are no shamefull questions.
Second: Why would you like to keep a debug window open when there is no program running in VS?

Also this article may be of interest.

First: There are no shamefull questions.

I find it a shameful question because I know how to do it, just for some odd reason it doesn't work well when i am running a c program.

Second: Why would you like to keep a debug window open when there is no program running in VS?

I am trying to view the program that i have compiled. A simple hello world is what i am trying to compile. I am doing this (to compile):

/* Hello World program */

#include<stdio.h>

main()
{
    printf("Hello World, I am writing in C");

}

I went through the link you provided, and i still can't keep that debug window open... even when i click (ctrl + f5)...

Any other clues and resources? Maybe a video in this case? I could be missing out on something.

I solved the problem, thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.