#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void main(int argc, char *argv[])
{
FILE *fp,*tfp;
if (argv[1] == NULL )
{
printf("Usage: fsplit filename
KBSize(Default 100KB) \n");
return ;
}
fp = fopen(argv[1],"rb");
if ( fp == NULL )
{
printf(" Could Not Open File %s
\n",argv[1] );
printf("Usage: fsplit filename
KBSize(Default 100KB) \n");
return ;
}
long splitsize = 100;
if ( argv[2] != NULL )
{
unsigned long temp;
temp = atol(argv[2]);
splitsize = temp ? temp
: 100 ;
}
unsigned long filelen;
unsigned int splitnos;
fseek(fp,0,2);
filelen = ftell(fp);
fseek(fp,0,0);
splitnos = filelen / (splitsize*1024);
unsigned long curlength=0;
unsigned long curfilecount;
char fileformation[20];
unsigned long tempcount=0;
for(curfilecount = 0;curfilecount<=splitnos;curfilecount++)
{
fileformation[0] = '\0';
ltoa(curfilecount,fileformation,10);
strcat(fileformation,".spt");
tfp = fopen(fileformation,"wb");
if ( tfp == NULL )
{
printf("Error Writing File %s",fileformation);
fclose(fp);
exit(0);
}
tempcount = 0;
while(tempcount != (splitsize*1024) )
{
tempcount++;
curlength++;
putc(getc(fp),tfp);
if( filelen == curlength
)
{
fclose(tfp);
fclose(fp);
return;
}
}
fclose(tfp);
}
}