Thread: How can I get my program to stop terminating?

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    2

    How can I get my program to stop terminating?

    Ok, I'm realtively new to C programming, but I have a light background in Visual Basic, Java, and HTML.

    I've been trying my hand at some very simple C programs, and I've run into something I'd like to change. I can get the programs to work just fine, but my problem is this: once they run through to completion, they simply end and the window closes. You can see my problem, because if the program specifies a certain output, I won't be able to read it, as it will quit immediately once it outputs the result.

    Here's some code from the first program I made (it's VERY simple, bear with me):

    Code:
        #include <stdio.h>
    
        int main()
        {
            printf("This is ass-easy.\n");
            return 0;
        }
    So far, the only way I've been able to prevent this is by putting the line "scanf("%d");" at the end, and I know there is a better way than that to fix my problem. If there's a cleaner way to get the program to stay open once it's finished working until I close it myself, I'd really like to know how.
    Last edited by mklickman; 09-19-2006 at 10:21 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Mmm, italics - that's new
    It's also unreadable as well.
    Perhaps read the how to post code threads first?

    As for the closing the window problem, it's in the FAQ.
    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.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    2
    First of all, I do appologise for cluttering the forum with a "n00b" question that was apparently answered in the FAQ; I hate seeing those myself. However, I honestly don't appreciate your condescending tone. I'm just looking for an answer to my question, and I'd appreciate not being heckled because of my formatting transgressions. Perhaps to simply make me aware of the error of my ways would have been a much easier way to go about it.

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    18
    hi mk,

    Quote Originally Posted by mklickman
    However, I honestly don't appreciate your condescending tone.
    stick around and you will. what you'll get sick of are the repetitive questions that can be answered by a simple search or reading of the FAQ's.

    and don't take it personally--it's part of the learning process. no pain, no gain.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. Early program stop problem
    By bmb_ksu in forum C Programming
    Replies: 9
    Last Post: 02-19-2006, 09:24 AM
  3. Stoping Program From Terminating Automatically
    By Undeadenemy in forum C Programming
    Replies: 5
    Last Post: 05-11-2003, 06:14 PM
  4. continuing program until ready to stop
    By jlmac2001 in forum C++ Programming
    Replies: 2
    Last Post: 01-19-2003, 07:19 PM