Hi,

I am have written a program in C but using Dev-C++ to run it. I have compiled my source code in c. however, my output window does not stay. I tried adding system(“PAUSE”); before return 0, but it does not work.

My program has both return 1 and return 0. How do i make the output window stay? Thanks

Dani AI

Generated

Short answer: the console closes because the program reaches its end (or an earlier return/exit) and Windows closes the window. The numeric return value (0 or 1) only becomes the process exit code — it does not keep the window open. As suggested, running the compiled .exe from a Command Prompt is an immediate way to see output without the window disappearing; as asked, posting the actual code will make it possible to point out early returns or exits that skip your pause.

Common, practical checks

  • Verify the pause code is actually reached: search for every return/exit path. If any path runs before your pause, the window will close.
  • If you added a pause but used “smart”/curly quotes (copied from Word or a web page), the compiler will reject that; make sure you used ASCII quotes.
  • Make the pause a single final step (cleanup label) so every exit path flows through it.

Simple, portable pause pattern
Place a single exit point and wait for input before returning:

#include <stdio.h>

int main(void) {
    int status = 0;
    /* program logic that may set status and jump to done */
done:
    printf("Press Enter to exit...");
    fflush(stdout);
    while (getchar() != '\n'); /* wait for Enter */
    return status;
}

Other options

  • Run the .exe from cmd.exe (cd to the folder, then run it) to inspect output and error messages.
  • Use the IDE debugger or set a breakpoint near program end to see why it exits early.
  • Redirect output to a file (program.exe > out.txt) if you need to preserve large output.

Post the relevant portion of the code (main and any early-return branches) if the program still closes — that will make it easy to point out exactly where the pause is being skipped.

Recommended Answers

All 2 Replies

Start a command prompt and run you program in it.

Dev-C++ is a bit long in the tooth you may want to try something a little more up-to-date like CodeBlocks.

post the code you compiled.

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.