Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6875977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:25:15+00:00 2026-05-27T04:25:15+00:00

I’m writing a web app that needs to use several ansi C functions to

  • 0

I’m writing a web app that needs to use several ansi C functions to crunch data. Another language, probably Java, will call the main C function to trigger the process. I want to return a value from the main C function for the Java script to evaluate success or not. I expect C’s use of exit() was created for this reason.

As I go about programming C, there are several times I run into situations that I could evaluate to examine whether or not the program is running correctly. For example, if I have a variable that can only equal "equation 1", "equation 2" or "equation 3", and then I use an

if(var==equation1) { 
  /*statements*/
} 
else if(var==equation2) {
  /*statements*/
} 
else if(var==equation3) {
  /*statements*/
}

statements to check which of the three possibilities it is, I could add an else { } to the end, whose contents I expect will never execute in a normally running program, to catch unexpected problems. I want to place an exit(EXIT_FAILURE) in this last else { } statement. If I understand it correctly, this will cause the program to terminate, and return a non-zero value to the Java calling program for it to detect. Is that correct?

Can I sprinkle this exit(EXIT_FAILURE) throughout various functions, not just main(), for the same reason?

Some questions about the mechanics of setting this up — Is the main function simply setup as: int main(void); assuming no input arguments for simplicity? That is, the int is needed to return the integer value called by the macro EXIT_FAILURE… is that right?

If the main() function called another function, and that function contained an exit(EXIT_FAILURE) statement, does that other function need to specifically include a return in its prototype, e.g. int function_one(void); where the int is needed to return the EXIT_FAILURE status, or is the EXIT_FAILURE macro self-sufficient in this regard, so that if the function_one wants to return, say, a character, then its prototype can be char function_one(void); and no worry about returning anything for EXIT_FAILURE in its prototype?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:25:15+00:00Added an answer on May 27, 2026 at 4:25 am

    The return type int of main is effectively the return value that the calling process sees. The general idea is that your main does this as any other function namely return EXIT_FAILURE. Whenever possible you should use this direct approach.

    The function exit can be used to shortcut all this and to return to the caller from any other function than main. But the return value of a function that uses exit has nothing to do with the fact that it might to a preliminary exit through exit. So you don’t have to change any prototype of your functions.

    Your other assumptions seem to be correct, and your use of exit to terminate an invalid invocation looks valid to me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am writing an app with both english and french support. The app requests
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.