Sample code for 30+ languages & platforms
Unicode C

Split File into Chunks

Demonstrates how to split a file into chunks.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkFileAccessW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkFileAccessW fac;
    const wchar_t *fileToSplit;
    const wchar_t *partPrefix;
    const wchar_t *partExtension;
    int maxChunkSize;
    const wchar_t *destDirPath;

    success = FALSE;

    fac = CkFileAccessW_Create();

    //  Any type of file may be split.  It doesn't matter if it's
    //  a binary file or a text file.
    fileToSplit = L"qa_data/hamlet.xml";

    partPrefix = L"hamlet";
    partExtension = L"part";
    maxChunkSize = 50000;
    destDirPath = L"qa_output";

    //  Splits hamlet.xml into hamlet1.part, hamlet2.part, ...
    //  Output files are written to the current working directory.
    //  Each chunk will be 50000 bytes except for the last which
    //  will be the remainder.
    success = CkFileAccessW_SplitFile(fac,fileToSplit,partPrefix,partExtension,maxChunkSize,destDirPath);

    if (success == TRUE) {
        wprintf(L"Success.\n");
    }
    else {
        wprintf(L"%s\n",CkFileAccessW_lastErrorText(fac));
    }



    CkFileAccessW_Dispose(fac);

    }