home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / dsplit.zip / DSPLIT.C < prev    next >
Text File  |  1993-07-14  |  2KB  |  59 lines

  1. /* File splitting utility */
  2.    Copywrite 1993 Gary Schrock
  3.    Permission granted to use, modify, and distribute the source and executables
  4.    as provisioned by the GNU software license.
  5.  
  6.    Last revision: 14 July 1993
  7. */
  8. #include <stdio.h>
  9.  
  10. void
  11. main() {
  12.   unsigned int split_size,count;
  13.   char filename[255],outfilename[255];
  14.   int filenamelength;
  15.   unsigned char in_word;
  16.   FILE *outfile,*infile;
  17.   char filecount;
  18.  
  19.   printf("File to split? ");
  20.   scanf("%s",filename);
  21.   printf("Size of pieces to create? ");
  22.   scanf("%ld",&split_size);
  23.  
  24.   infile=fopen(filename,"rb");
  25.   strcpy(outfilename,filename);
  26.   filenamelength=strlen(outfilename);
  27.   filecount=0;
  28.   outfilename[filenamelength]='.';
  29.   outfilename[filenamelength+1]=filecount+'0';
  30.   outfilename[filenamelength+2]='\0';
  31.   outfile=fopen(outfilename,"wb");
  32.   count=0;
  33.   while(fread(&in_word,sizeof(unsigned char),1,infile)>0) {
  34.     fwrite(&in_word,sizeof(unsigned char),1,outfile);
  35.     count++;
  36.     if (count==split_size) {
  37.       fclose(outfile);
  38.       filecount++;
  39.       strcpy(outfilename,filename);
  40.       filenamelength=strlen(outfilename);
  41.       if (filecount<10) {
  42.         outfilename[filenamelength]='.';
  43.         outfilename[filenamelength+1]=filecount+'0';
  44.         outfilename[filenamelength+2]='\0';
  45.       } else {
  46.         outfilename[filenamelength]='.';
  47.         outfilename[filenamelength+1]=filecount/10+'0';
  48.         outfilename[filenamelength+2]=filecount%10+'0';
  49.         outfilename[filenamelength+3]='\0';
  50.       }
  51.       outfile=fopen(outfilename,"wb");
  52.       count=0;
  53.     }
  54.   }
  55.   fclose(infile);
  56.   fclose(outfile);
  57. }
  58.  
  59.