// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
#include <iostream>
#include <stdlib.h>

using namespace std;

int Split(char* dest[10], char* src, unsigned int length, char splitChar, char strChar);

int main(int argc, char *argv[])
{
    char src[] = "This is a test \"hello world\"";
    char* items[10];
    int idx, len;
    len = Split(items, src, strlen(src), ' ', '"');
   
    for(idx = 0; idx < len; idx++)
        cout << "#" << idx << "\t[" << items[idx] << "]" << endl;
   
    return 0;
}

int Split(char* dest[10], char* src, unsigned int length, char splitChar, char strChar)
{
    bool esc = false;
    int idx = 0;
    dest[idx] = src;
    idx++;
    for(int loc=0;loc<length;loc++)
    {
        if(src[loc] == splitChar && !esc)
        {
            src[loc] = '\0';
            dest[idx] = src + loc + 1;
            idx++;
        }
        else if(src[loc] == strChar)
        {
            esc = !esc;
        }
        else
        {
            // nothing
        }
    }
    return idx;
}
