title: c code to split files
body: <p>I have written a program to split files into multiple part in C.  The code below is what I've been using to split text files which work correctly but it isn't able to split <code>.mp3</code> files:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  
  main()
  {
      char fn[250], ch, nfn[250];
      long int size, n, k;
      int i;
      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);
  
      i = 1;
      k = size/n;
      rewind(f);
      sprintf(nfn, "%s.%d", fn, i);
      ft = fopen(nfn, "wb");
      while(1)
      {
          ch = fgetc(f);
          if (ch==EOF)
              break;
          fputc(ch, ft);
          if (ftell(f)==(i*k))
          {
              i = i+1;
              fclose(ft);
              sprintf(nfn, "%s.%d", fn, i);
              ft=fopen(nfn, "wb");
          }
      }
  }
  </code></pre>
  
  <p>It just creates one file with the name <code>test.mp3.1</code> and stoped</p>