title: How to create an exact copy of file in c
body: <p>I want to create an exact copy of a file(.bmp) in c </p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  int main()
  {
      FILE *str,*cptr;
  
      if((str=fopen("org.bmp","rb"))==NULL)
      {
          fprintf(stderr,"Cannot read file\n");
          //return 1;
      }
  
      if((cptr=fopen("copy.bmp","wb"))==NULL)
      {
          fprintf(stderr,"Cannot open output file\n");
          //return 1;
      }
  
      fseek(str, 0, SEEK_END);
      long size=ftell(str);
      printf("Size of FILE : %.2f MB \n",(float)size/1024/1024);
      char b[2];
  
      for(int i=0;i&lt;size;i++)
      {
          fread(b,1,1,str);
          fwrite(b,1,1,cptr);
      }
  
      fseek(cptr, 0, SEEK_END);
      long csize=ftell(str);
      printf("Size of created FILE : %.2f MB \n",(float)csize/1024/1024);
      fclose(str);
      fclose(cptr);
  
      return 0;
  }
  </code></pre>
  
  <p>Although it creates a file of the same size but windows throws an error while trying to view the newly created copy of bitmap.
  Why is this happening? </p>