#include <stdio.h>
#include <string.h>
int main(int argc,char** argv)
{
    if (argc < 2)
    {
        printf("%s","I need one parameter which is the file to be split\n");
        return 0;
    }
    int outFileSeq = 0;
    double sourceFileOffset = 0;
    FILE *inpFile = fopen(argv[1],"rb");
    if(inpFile == NULL)
    {
        printf ("%s","Could not get the inputFile\n");
        return 1;
    }
    int nread = -1;
    while(!feof(inpFile) && nread != 0)
    {
        char outFileName[20];
        char buffer[513];
        sprintf(outFileName,"%s_part.%d",argv[1],outFileSeq++);
        FILE* outFile = fopen(outFileName,"wb");
        if(outFile == NULL)
        {
            printf ("Could not create %s\n",outFileName);
            printf ("%s","Please delete the files already created yourself");
        }
        printf ("writing to %s\n",outFileName);
        unsigned long outFileOffset = 0;
        while (outFileOffset < 1024 * 1024)
        {
            memset(buffer,0,512);
            nread = fread(buffer,1,512,inpFile) ;
            {
                int nwrite = fwrite(buffer,1,nread,outFile);
                outFileOffset += nread;
            }
            if(feof(inpFile) || nread == 0)
                break;
        }
        fclose(outFile);
    }
    fclose(inpFile);
    printf ("use this command on DOS\n\t copy \b \"%s_part.0\"",argv[1]);
    for (int i = 1 ; i < outFileSeq ; i ++)
    {
        printf (" + \"%s_part.%d\"",argv[1],i);
    }
    printf (" \"%s\"\nTo join the files\n\n",argv[1]);

    printf ("use this command on Unix (any flavor)\n\t cat",argv[1]);
    for (int i = 0 ; i < outFileSeq ; i ++)
    {
        printf (" %s_part.%d ",argv[1],i);
    }
    printf (" > %s\nTo join the files\n\n",argv[1]);
}


Hosted by www.Geocities.ws

1