title: using fopen to write in a txt in c language
body: <p>I am studying computer science and I am supposed to create a c shell for a project.In this part of the project I have to write the code for these types of commands : "sort &lt; in.txt > out.txt". My problem is that after using execlp so as to sort my "in.txt", i cannot write the result in the "out.txt" that I create. My code is like:</p>
  
  <pre><code>outfile = fopen("out.txt", "w");
  dup2((int) outfile , 0);
  dup2((int) outfile , 1);
  close (outfile);
  </code></pre>
  
  <p>Does anyone know what I have to fix? Thank you.</p>