How to print "\r" to a file
<p>I want to show a progress bar in my program so I add this</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;unistd.h&gt;

int main() {
    puts("begin");
    for (int i = 0; i &lt; 100; i++) {
        printf("%d%% finished.\r", i);
        fflush(stdout);
        usleep(100000);
    }
    puts("end");
}
</code></pre>

<p>when it outputs to <code>stdout</code> it shows nicely a line indicating the current progress. </p>

<p>However if I direct its output to a file, then all the lines with <code>printf("%d%% finished.\r", i);</code> are missing. </p>

<p>Is it possible to keep all the lines in a file?</p>