title: How do I split a text file into parts in C?
body: <p>Suppose I have a text file that says:
  <em>This file has plain text</em></p>
  
  <p>Now, I want to divide this text file into 'n' number of parts with equal characters.
  Suppose the user wants three divisions, then 1.txt, 2.txt and 3.txt should be created, with about 8 characters each.</p>
  
  <p>(The next part of this program is to rejoin these files back into the original state but I'm sure I'll be able to do that myself If I can get help with this first part).</p>
  
  <p>Can you guys guide me in this matter?</p>
  
  <p>Language used is C.</p>
  
  <pre><code>void main(int argc, char** argv)
  {
  int iChunkNo=0;
  char cFileName[30];
  
  iChunkNo = atoi(argv[2]);
  strcpy(cFileName, argv[1]);
  
  printf("The file will be divided into %d chunks \n", iChunkNo);
  
  FILE* file_read_pointer;
  file_read_pointer = fopen(cFileName, "r");
  
  int iCount=0;
  char ch;
  
  while (1) 
  {
          ch = fgetc(file_read_pointer);
          if (ch == EOF)
              break;
          ++iCount;
  }
  
  printf("The number of characters in the file is: %d \n", iCount);   
  
  int iCharPerFile = 0;
  iCharPerFile = iCount/iChunkNo;
  
  printf("The number of characters per chunk file will be: %d \n", iCharPerFile);
  
  FILE* file_write_pointer;   
  
  int j=1;
  for(j; j&lt;=iChunkNo; j++)
  {   
      char num[5] = {j};
      char ext[4] = {"txt"};
  
      char name[15];
      sprintf(name, "%d.%s", j, ext);     
  
      FILE* file_write_pointer;
      file_write_pointer = fopen(name, "w");
  }
  
  int i=0;
  
  for(i; i&lt;iCharPerFile; i++)
  {
      char temp;
      temp = fgetc(file_read_pointer);
      //fputc(temp, file_write_pointer);
      fprintf(file_write_pointer, "%c", temp);
  }
  }
  </code></pre>