// Split
// Creates array of char* pointers to tokens, seperated by 'c'
// a is array, al is number of elements
// returns true on success, false on fail.
// if success, called should free a[0] (the string), and "a" itself (the arrya of pointers)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int split(char *s, char c, char ***a, int *al) {
char *ce = NULL; // current element
char *ne = NULL; // next element
char *p = NULL;
int i = 0;
if(!s) {
return -1;
}
// first pass: just count
p = s;
*al = 1;
while(1) {
p = strchr(p,c);
if(!p) {
break;
}
p++;
(*al)++;
}