Thread: Simple Question: How do yo uend a C program?

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    5

    Simple Question: How do yo uend a C program?

    In C I don'tk now how to end a program. Like if you call a function and if something appears to be true or false or not equal to something and then ednd the program. or like use end program in an if statement or something. Can someobody please hurry up and tell me!

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    >>Can someobody please hurry up and tell me!

    Ok....Ok.....

    try exit();

    It is defined in the <stdlib.h>

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    5

    YOU THE ILLEST *whoever you are*

    How about you answer another question for me. In C, how do you make it so that it accept some text right. And then see if certain words are in that text.

  4. #4
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    Use strcmp to see if the word's right

    check out the functions in stdio.h to get your input.

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    YOU THE ILLEST *whoever you are*

    Uhh.....what???

  6. #6
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    If in a function should happen that should result in ending the program, the function should return an error-value. The calling function should notice that something had gone wrong and return an error-value. This goes on until the main()-function is reached. The main function should note that something has gone wrong and will return an error-value to the environment.

    When you need to use a function like exit(), your program is not very well structured. Since if it was, then you wouldn't need it.

  7. #7
    Registered User breed's Avatar
    Join Date
    Oct 2001
    Posts
    91
    shiro is right, you should only use the exit() function if an error occurs to close the prog.
    the prog should end after its completed all statements within the main()
    {
    if( (open_whatever) !=NULL);
    {
    ouput_whatever;
    exit(1);
    }
    input_whatever;
    loop(somat)
    {
    do_whatever;
    }
    output_whatever;
    close_whatever;
    }end main

    fordy that reponse made me!
    Before you judge a man, walk a mile in his
    shoes. After that, who cares.. He's a mile away and you've got
    his shoes.
    ************William Connoly

  8. #8
    Registered User
    Join Date
    Jan 2002
    Posts
    22

    Re: How do you end a C program?

    you could simply use exit(0).
    -------------------------
    Gerald.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Possibly simple question
    By PAragonxd in forum C++ Programming
    Replies: 1
    Last Post: 09-14-2008, 02:43 AM
  2. Replies: 16
    Last Post: 09-30-2007, 11:08 PM
  3. Mystery bug in simple program? - I am beginner
    By archie123 in forum C++ Programming
    Replies: 7
    Last Post: 04-08-2005, 07:23 AM
  4. question about the loop in case conversion program
    By Elhaz in forum C++ Programming
    Replies: 8
    Last Post: 09-20-2004, 04:06 PM
  5. simple program question...
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 08-31-2001, 07:34 PM