Sample code for 30+ languages & platforms
Unicode C

Append Encoded Binary Data to StringBuilder

Demonstrates how to append encoded binary data to the contenets of a StringBuilder.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkBinDataW.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkBinDataW bd;
    HCkStringBuilderW sb;

    success = FALSE;

    bd = CkBinDataW_Create();

    success = CkBinDataW_LoadFile(bd,L"qa_data/jpg/starfish.jpg");
    if (success == FALSE) {
        wprintf(L"Failed to load file.\n");
        CkBinDataW_Dispose(bd);
        return;
    }

    //  For example, let's say we want construct simple JSON containing the base64 representation of the above JPG file.
    sb = CkStringBuilderW_Create();
    CkStringBuilderW_Append(sb,L"{ \"jpg\": \"");
    //  GetEncodedSb appends the enocded representation of the binary data to the StringBuiler passed in the 2nd arg.
    CkBinDataW_GetEncodedSb(bd,L"base64",sb);
    CkStringBuilderW_Append(sb,L"\" }");

    wprintf(L"%s\n",CkStringBuilderW_getAsString(sb));

    //  Output looks like this:
    //   { "jpg": "/9j/4AAQSkZJRgABAg...rcQ+vo//2Q==" }


    CkBinDataW_Dispose(bd);
    CkStringBuilderW_Dispose(sb);

    }