title: Understanding Buffering in C
body: <p>I am having a really hard time understanding the depths of buffering especially in C programming and I have searched for really long on this topic but haven't found something satisfying till now.</p>
  
  <p>I will be a little more specific:
  I do understand the concept behind it (i.e. coordination of operations by different hardware devices and minimizing the difference in speed of these devices) but I would appreciate a more full explanation of these and other potential reasons for buffering (and by full I mean full the longer and deeper the better) it would also be really nice to give some concrete Examples of how buffering is implemented in I/O streams. </p>
  
  <p>The other questions would be that I noticed that some rules in buffer flushing aren't followed by my programs as weirdly as this sounds like the following simple fragment:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(void)
  {
      FILE * fp = fopen("hallo.txt", "w");
  
      fputc('A', fp);
      getchar();
      fputc('A', fp);
      getchar();
  
      return 0;
  }
  </code></pre>
  
  <p>The program is intended to demonstrate that impending input will flush arbitrary stream immediately when the first getchar() is called but this simply doesn't happen as often as I try it and with as many modifications as I want &mdash; it simply doesn't happen as for <code>stdout</code> (with <code>printf()</code> for example) the stream is flushed without any input requested also negating the rule therefore am I understanding this rule wrongly or is there something other to consider</p>
  
  <p>I am using Gnu GCC on Windows 8.1.</p>
  
  <p>Update:</p>
  
  <p>I forgot to ask that I read on some sites how people refer to e.g. string literals as buffers or even arrays as buffers; is this correct or am I missing something?
  Please explain this point too.</p>