title: What return value should you use for a failed function call in C?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/385975/error-handling-in-c-code">Error handling in C code</a>  </p>
  </blockquote>
  
  
  
  <p>Let's say you have a function:</p>
  
  <pre><code>int MightWork(){
    // if it works
    return x;
  
    // if it fails
    return y;
  
  }
  </code></pre>
  
  <p>what should x and y be?</p>
  
  <p>because I have another function:</p>
  
  <pre><code>if (MightWork){
    // do stuff #1
  }else{
    // do stuff #2
  }
  </code></pre>
  
  <p>I know for this particular example, using a return value of 1 will take the second code block to "do stuff # 1" and using a return value of 0 will take the second code block to "do stuff #2"</p>
  
  <p>My question is what is preferred style in C to do this? Does a return value of 0 for a function indicate success and any other value indicates failure? Or vice versa? Or values under 0?</p>
  
  <p>I'd like to make sure I'm writing my C code with the current style. Thanks!</p>