char** sliceString( char* __in string, char* __in token, int* __out tokenGot ) { char** newstring = NULL; char* separator = NULL; int curSize = 1; if( NULL == string || NULL == token ) { return NULL; } newstring = (char**)malloc( curSize * sizeof( char* ) ); if( NULL == newstring ) { return NULL; } separator = strtok( string, token ); while( NULL != separator ) { // Getting new space newstring[curSize-1] = malloc( strlen( separator )+sizeof(char) ); // Space reserved? if( NULL == newstring[curSize-1] ) { return NULL; } // copy that shit sprintf( newstring[curSize-1], "%s\0", separator ); // increment the lines curSize++; // allocte new line newstring = (char**)realloc( newstring, curSize * sizeof( char* ) ); // getting new token separator = strtok( NULL, token ); } *tokenGot = curSize-1; return newstring; }