title: How to redirect printf() to file and then back to console
body: <p>I am working on a project that requires me to have output from within a mini shell on my C program to output to a file. <strong>Using <code>./program &gt; file.txt</code> will NOT work</strong>.</p>
  
  <p>I have a mini shell program that runs small commands, and I would like to make it so when someone has a <code>&gt; filename</code> at the end of a command, it will redirect all text from <code>printf()</code> to a file and instead of the console, and then redirect it back into the console. </p>
  
  <p>How can I accomplish this in <strong>C</strong>?</p>