Results 1 to 2 of 2

Thread: New to programming

  1. #1

    Default New to programming

    I am starting to learn C and as I put in the sample code it the command window does not stay open to see the output. It flashes then closes.

    I am using Bloodshed Dev C++ IDE.

  2. #2


    I found my answer.

    If you execute your program (with or without parameters), you may notice something peculiar; a console window will pop up, flash some text and disappear. The problem is that, if directly executed, console program windows close after the program exits. You can solve this problem one of two ways:

    Method 1 - Scaffolding:
    Add the following code before any return statement in main() or any exit() or abort() statement (in any function):

    /* Scaffolding code for testing purposes */
    cin.ignore(256, '\n');
    cout << "Press ENTER to continue..." << endl;
    /* End Scaffolding */

    This will give you a chance to view any output before the program terminates and the window closes.

    Method 2 - Command-prompt:
    Alternatively, instead of using Dev-C++ to invoke your program, you can just open an MS-DOS Prompt, go to the directory where your program was compiled (i.e. where you saved the project) and enter the program name (along with any parameters). The command-prompt window will not close when the program terminates.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts