title: printf prints to a binary file in c
body: <p>I have a binary file that I open, modify, and close. And then I <code>printf</code> to the console.</p>
  
  <p>This all works fine, but I realized just now that it's appending whatever I'm printing to the console to the end of the binary file, and it makes no difference whether or not the file is open or closed.</p>
  
  <p>The same thing happens with <code>fprintf</code>.</p>
  
  <p>What's going on here? Is there something I don't understand about file I/O?</p>
  
  <p>Update: Here's the code:</p>
  
  <pre><code>FILE *out = fopen("test","wb+");
  fseek(out,0,SEEK_END);
  fwrite("test",1,10,out);
  fwrite("test",1,10,out);
  fwrite("test",1,10,out);
  int pos = ftell(out);
  fwrite(&amp;pos,sizeof(int),1,out);
  fclose(out);
  fprintf(stdout,"%s","hello");
  </code></pre>