title: Bad file descriptor
body: <p>I'm learning about file descriptors and I wrote this code:</p>
  
  <pre><code>#include &lt;unistd.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;fcntl.h&gt;
  
  int fdrd, fdwr, fdwt;
  char c;
  
  main (int argc, char *argv[]) {
  
      if((fdwt = open("output", O_CREAT, 0777)) == -1) {
          perror("Error opening the file:");
          exit(1);
      }
  
      char c = 'x';
  
      if(write(fdwt, &amp;c, 1) == -1) {
          perror("Error writing the file:");
      }
  
      close(fdwt);
      exit(0);
  
  }
  </code></pre>
  
  <p>, but I'm getting: <code>Error writing the file:: Bad file descriptor</code></p>
  
  <p>I don't know what could be wrong, since this is a very simple example.</p>