C
30
filesplitter
Guest on 24th June 2022 02:47:31 PM
#include <stdlib.h>
#include <stdio.h>
void usage(char *progname)
{
printf("Usage: %s <input file name> <output root name>\n"
"where the output files will be named\n"
"<output root name>.1 ,<output root name>.2, etc\n",
progname );
}
int main(int argc, char * argv[])
{
const long int flopsize = 1430000;
long int noutchars;
char *poutname;
int noutfile = 0;
int inchar;
FILE *fpin, *fpout;
if( argc != 3 ) usage(argv[0]);
fpin
= fopen(argv
[1],"r");
if( fpin == NULL )
{
perror("Cannot open input file.\n");
usage(argv[0]);
}
if( poutname == NULL )
{ perror("Bad outfile name?\n");
usage(argv[0]);
}
noutchars = 0;
while( inchar != EOF )
{
if( noutchars >= flopsize )
{
noutchars = 0;
}
if( noutchars == 0 )
{
sprintf(poutname
,"%s.%d", argv
[2], ++noutfile
);
printf("Writing file %s ...\n", poutname
);
fpout
= fopen(poutname
,"w");
}
putc((char) inchar
, fpout
);
noutchars++;
}
if(noutchars == 0)
return(0);
}