Simple Question: How do yo uend a C program?

This is a discussion on Simple Question: How do yo uend a C program? within the C Programming forums, part of the General Programming Boards category; In C I don'tk now how to end a program. Like if you call a function and if something appears ...

  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,789
    >>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,825
    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,789
    YOU THE ILLEST *whoever you are*

    Uhh.....what???

  6. #6
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    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, 03:43 AM
  2. Replies: 16
    Last Post: 10-01-2007, 12:08 AM
  3. Mystery bug in simple program? - I am beginner
    By archie123 in forum C++ Programming
    Replies: 7
    Last Post: 04-08-2005, 08:23 AM
  4. question about the loop in case conversion program
    By Elhaz in forum C++ Programming
    Replies: 8
    Last Post: 09-20-2004, 05:06 PM
  5. simple program question...
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 08-31-2001, 08:34 PM

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