title: C reading/writing to a file in binary mode
body: <p>I created a File of 4000 blocks with a blocksize of 4096 Bytes. 
  Now I want to manipulate single blocks and read them again without changeing the files' size.
  Actually I want to write blocks out of another file to specific blocks in the file I created.
  Therefore I am opening the Files in binarymode like this:</p>
  
  <pre><code>FILE * storeFile=fopen(targetFile, "wb");  // this one I created before
  FILE * sourceFILE=fopen(sourceFile,"rb");
  </code></pre>
  
  <p>now I am trying to read stuff to a pointer</p>
  
  <pre><code>char * ptr=malloc(4096);
  ...
  for(i=0; i&lt;blocks_needed; i++)
  {
      fread(ptr,4096,1,sourceFile);
      // now I am going to the position of the blocks I want to write to
      fseek(storeFile,freeBlocks[i]*4096,SEEK_SET);
      // and now I am writing it to the File I created before
      fwrite(ptr,4096,1,storeFile);
  ...
  }
  </code></pre>
  
  <p>For some reason the File I created before changes it's size and becomes a copy of the file I wanted to write into it.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Thank you in advance!</p>