title: Error when split files by code c
body: <p>I'm coding a program which split files, but I got some problem when run it, and  I don't know how to resolve it.<br>
  Give me some intruction. All files that split sometimes 0kb, sometimes have data. It confused me. </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  void main()
  {
      char *fn = new char[250];
      char *nfn = new char[250];
      long int size, n, size_per_pack;
      FILE *f, *ft; //file and temp file
  
      printf("enter the file you want to split with full path : ");
      scanf("%s", fn);
      printf("enter the number of parts you want to split the file : ");
      scanf("%ld", &amp;n);
  
      f = fopen(fn, "rb");
      if (f == NULL)
      {
          printf("couldn't open file");
          exit(0);
      }
  
      fseek(f, 0, 2);
      size = ftell(f);
      printf("the size of the file in bytes is : %ld\n", size);
  
      size_per_pack = size / n;
      rewind(f);
      int m = 0;
      char *s1 = new char[size_per_pack];
      for (int j = 1; j &lt;= n; j++)
      {
          sprintf(nfn, "%s.%d", fn, j);
          ft = fopen(nfn, "wb");
          fread(s1, 1, size_per_pack, f);
          fwrite(&amp;s1, 1, size_per_pack, ft);
          rewind(ft);
          int present = ftell(f);
          int present2 = ftell(ft);
      }
      delete[]s1; 
      delete[]fn; 
      delete[]nfn;
      _fcloseall();
  }
  </code></pre>