#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    12
    Rep Power
    0

    program ends in miliseconds?


    i wroe the hello world program but after compiling it using bloodshed, i go to the directory where i saved it click on the file and a dos window comes up saying hello world for litrully miliseconds i had to keep clicking it to see that it said hello world why does it shut its self down straight away? :confused:
  2. #2
  3. Crypto-Con
    Devshed Supreme Being (6500+ posts)

    Join Date
    Apr 2004
    Location
    Frisco, Texas
    Posts
    6,704
    Rep Power
    1236
    The window will automatically close when the code finishes running, you need to hold it in some way...

    Place getchar(); at the end of your code, this will wait until you press the 'enter' key before continuing....
    - "Cryptographically secure linear feedback shift register based stream ciphers" -- a phrase that'll get any party started.
    - Why know the ordinary when you can understand the extraordinary?
    - Sponsor my caffeine addiction! (36.70 USD received so far -- Latest donor: Mark Foxvog.
    )
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    Lawrence, Kansas [KU]
    Posts
    1,559
    Rep Power
    15
    because the function is over. usually if you run it through debuggers you can have it do something like "press any key to continue" so you can actually see your output. but if you can't do that then just ask for an input from the user at the end of the program, that way it will pause and you can read it for as long as you want.
  6. #4
  7. No Profile Picture
    Maciej Ignacy Arciuch
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Location
    Warsaw, Poland
    Posts
    56
    Rep Power
    11
    Place
    Code:
    system("PAUSE");
    at the end of your program.

    Hope this helps,
    Matthew
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    272
    Rep Power
    19
    Run it from a command shell.

    Comments on this post

    • kicken agrees : As it was ment to be run.
  10. #6
  11. Lord of Dorkness
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2004
    Location
    Central New York. Texan via Arizona, out of his element!
    Posts
    8,524
    Rep Power
    3314
    One person's "pause" is another person's "PAUSE." For a learning exercise such as yours, pick the solution from the above that works in your environment and suits your goal (least exasperation, easiest, quickest, most productive, whatever), bearing in mind that instant gratification may breed bad habits.
    Functionality rules and clarity matters; if you can work a little elegance in there, you're stylin'.
    If you can't spell "u", "ur", and "ne1", why would I hire you? 300 baud modem? Forget I mentioned it.
    DaWei on Pointers Politically Incorrect.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Montreal, Canada
    Posts
    486
    Rep Power
    11
    Originally Posted by 3dfxMM
    Run it from a command shell.
    exactly

    if you are in windows
    go on Run Commands, type "cmd" + enter, it should prompt a console, then just go run your application, you will read it without problem ;) !
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Location
    Colorful Colorado
    Posts
    743
    Rep Power
    0
    i havent done this in a while, and i dont have a windows machine on which to test this, but i do believe that you can edit a .pif file to make the console window stay open after the program stops executing. of course this could all be a figment of my imagination.
  16. #9
  17. Lord of Dorkness
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2004
    Location
    Central New York. Texan via Arizona, out of his element!
    Posts
    8,524
    Rep Power
    3314
    Start by reading the FAQ, first post at the top of the forum. Follow the thread that relates to the console window slamming shut on you. There are numerous explanations, examples, and work-arounds. It's an uncommonly common question.
    Functionality rules and clarity matters; if you can work a little elegance in there, you're stylin'.
    If you can't spell "u", "ur", and "ne1", why would I hire you? 300 baud modem? Forget I mentioned it.
    DaWei on Pointers Politically Incorrect.
  18. #10
  19. Registered User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Nov 2004
    Location
    Ottawa, ON
    Posts
    2,059
    Rep Power
    49
    cin.get();
    or system("PAUSE");
    or getchar();
    or (maybe I'm just guessing) getint();, getfloat();
    and many others
    C++ right?
    Last edited by pmam21; October 19th, 2005 at 11:43 PM.
  20. #11
  21. Lord of Dorkness
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2004
    Location
    Central New York. Texan via Arizona, out of his element!
    Posts
    8,524
    Rep Power
    3314
    He asked back in June, pmam. One would hope he's not still grappling around inside his tower looking for the disappeared window.
    Functionality rules and clarity matters; if you can work a little elegance in there, you're stylin'.
    If you can't spell "u", "ur", and "ne1", why would I hire you? 300 baud modem? Forget I mentioned it.
    DaWei on Pointers Politically Incorrect.
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2006
    Posts
    1
    Rep Power
    0

    anything


    Include the file #inlcude <conio.h> and call the function getch( ); at the end of the programm. By calling this function the output will be closed only when you hit any key.
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    51
    Rep Power
    11
    Ibindu, please don't reply to long-dead threads. The last post in this thread was over a year ago, which itself was several months after the question was asked.

    There is a line above each post that says when it was made.

    Comments on this post

    • Anticastleism disagrees : Why worry about it?
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    Smile


    Originally Posted by macar
    Place
    Code:
    system("PAUSE");
    at the end of your program.

    Hope this helps,
    Matthew
    :) thanks...

IMN logo majestic logo threadwatch logo seochat tools logo