Skip to content

Instantly share code, notes, and snippets.

@alsamitech
Created April 22, 2021 06:39
Show Gist options
  • Save alsamitech/6dedd968483644b0d92ebfe23538ef9a to your computer and use it in GitHub Desktop.
Save alsamitech/6dedd968483644b0d92ebfe23538ef9a to your computer and use it in GitHub Desktop.
The Compound Tokenizer, but faster.
char** atokl(char* InC, char* delim, long unsigned int* len){
long unsigned int capacity=32;
char** tok=(char**)malloc(capacity*sizeof(char**));
//printf("%p\n", tok);
tok[0]=strtok(strdup(InC), delim);
{
long unsigned int i=1;
while(tok[i-1]!=NULL){
if(i+2>=capacity){
capacity+=32;
tok=(char**)realloc(tok, capacity*sizeof(char**));
if(!tok){
// something failed
return 0x0;
}
}
tok[i]=strtok(NULL, delim);
//printf("%p\n", tok[i]);
i++;
}
*len=i;
/*EBRACE*/}
return tok;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment