title: fwrite fails to write value 10 (0x0A)
body: <p>I was experimenting on creating BMP files from scratch, when I found a weird bug I could not explain. I isolated the bug in this minimalist program:</p>
  
  <pre><code>int main()
  {
      FILE* ptr=NULL;
      int success=0,pos=0;
      ptr=fopen("test.bin","w");
      if (ptr==NULL)
      {
          return 1;
      }
      char c[3]={10,11,10};
      success=fwrite(c,1,3,ptr);
      pos=ftell(ptr);
      printf("success=%d, pos=%d\n",success,pos);
      return 0;
  }
  </code></pre>
  
  <p>the output is:</p>
  
  <pre><code>success=3, pos=5
  </code></pre>
  
  <p>with hex dump of the <code>test.bin</code> file being:</p>
  
  <pre><code>0D 0A 0B 0D 0A
  </code></pre>
  
  <p>In short, whatever value you put instead of <code>11</code> (0x0B), <code>fwrite</code> will write it correctly. But for some reason, when <code>fwrite</code> comes across a <code>10</code> (0x0A) - and precisely this value - it writes <code>0D 0A</code> instead, that is, 2 bytes, although I clearly specified 1 byte per write in the <code>fwrite</code> arguments. Thus the 3 bytes written, as can be seen in the <code>success</code> variable, and the mysterious <code>5</code> in the <code>ftell</code> result.</p>
  
  <p>Could someone please tell me what the heck is going on here...and why 10, why not 97 or 28??</p>
  
  <p>Thank you very much for your help!</p>
  
  <p>EDIT: oh wait, I think I have an idea...isn't this linked to \n being 0A on Unix, and 0D 0A on windows, and some inner feature of the compiler converting one to the other? how can I force it to write exactly the bytes I want?</p>