void FreeSplit(char **data) { int i; if(data == NULL) return; for(i = 0; i < 3; i++) { if(data[i]) free(data[i]); } free(data); } char **SplitConstruct(const char *var) { char **retval = NULL; const char *ptr = NULL; int len = 0, i = 0; ptr = strstr(var, "REM IF "); if(ptr == NULL) return NULL; ptr += 7; // 7 == strlen("REM IF "); retval = (char **)malloc(sizeof(char *) * 3); memset(retval, 0, sizeof(char *) * 3); for(i = 0; i < 3; i++) { ptr = strchr(ptr, ' '); if(ptr == NULL) break; len = ptr - var; retval[i] = (char *)malloc(len + 16); strncpy(retval[i], ptr, len); ptr += len + 1; } while(0); if(i != 3) { // error FreeSplit(retval); retval = NULL; } return retval; }