title: fdopen and fprintf
body: <p>The following code is expected to write "some text" to demo.txt, but it doesn't work:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;unistd.h&gt;
  
  int main(int argc, char *argv[])
  {
      FILE *fp;
      int fd;
  
      if ((fd = open("demo.txt", O_RDWR)) == -1) {
          perror("open");
          exit(1);
      }
      fp = fdopen(fd, "w");
      fprintf(fp, "some text\n");
      close(fd);
      return 0;
  }
  </code></pre>