executable file closes. why?

This is a discussion on executable file closes. why? within the C Programming forums, part of the General Programming Boards category; just finished my program but now when i run only the executable as soon as i enter the filename and ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    494

    executable file closes. why?

    just finished my program but now when i run only the executable as soon as i enter the filename and hit enter, the exe closes. any ideas what i need to do?
    When no one helps you out. Call google();

  2. #2
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    Quote Originally Posted by InvariantLoop
    just finished my program but now when i run only the executable as soon as i enter the filename and hit enter, the exe closes. any ideas what i need to do?
    That's an extremely common problem. There are a few ways you can fix that problem:

    One is cin.get(), which is included in the <iostream.h> file, and another solution you can use <stdlib.h> and use system("pause"). Just call one of those functions right before you return from main.
    Last edited by Krak; 01-29-2005 at 01:50 PM.

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    how do u pause? give me an example, i put it in my code as follows
    Code:
    return 1;
    system ("pause");
    and still no go,
    When no one helps you out. Call google();

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    You need to put the pause before the return statement. And also, you should always return 0 if there wasn't an error.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,337
    Try swapping those two statements around.
    No use pausing AFTER you return.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    yep it works now. thanks again ehehe
    When no one helps you out. Call google();

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 08:35 AM
  2. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  3. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 04:02 AM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21