title: print to stderr is not reaching stderr
body: <p>I am writing a &quot;shell&quot; project in C and when I try to write to stderr (when an error occurs), the message is printed (stdout) but the output string does not reach stderr (a script tests this, and  we can assume it works).</p>
  <p>This is how my script is structured</p>
  <pre><code>int main(int argc, char * argv) {
      ...
      while(some_expression) {
          switch(other_expression) {
              ...
              case k:
                  raise_error();
                  break;
              ...
          }
      }
  }
  </code></pre>
  <p>And raise_error() looks like this:</p>
  <pre><code>void raise_error() {
      char error_message[30] = &quot;An error has occurred\n&quot;;
      write(STDERR_FILENO, error_message, strlen(error_message));
  }
  </code></pre>
  <p>When I check the file that should contain the error message (generated by the test script) it is empty, but the error message appears in the console output (stdout). If remove everything inside main, and just put raise_error(), it works correctly and the error message appears in stderr file. I also modified raise_error() in the next way:</p>
  <pre><code>void raise_error() {
      printf(&quot;Raise error method is reached&quot;);
      char error_message[30] = &quot;An error has occurred\n&quot;;
      write(STDERR_FILENO, error_message, strlen(error_message));
  }
  </code></pre>
  <p>My output then looks like this:</p>
  <pre><code>An error has occurred
  Raise error method is reached
  </code></pre>
  <p>What I may be doing wrong?</p>