title: Why does open make my file descriptor 0?
body: <p>I'm working on a program that is using a pipe and forks and need to change the write end to an output file.  But when I open a file the file descriptor is 0 which is usually stdin but which I think is the cause of some of my problems.  Here is my code</p>
  
  <pre><code>if (outputfd = open("file", O_RDWR | O_CREAT | O_TRUNC) == -1) 
  {
      // open failed
  }
  </code></pre>
  
  <p>Can someone let me know why it is 0? Or how to fix it?</p>