int main() { char *html_buf, *buf, **tokens; const char delimiters[] = " \r\n"; int cnt, num_of_str; cnt = num_of_str = 0; if ( (html_buf = malloc(BUF_APP_Q)) == NULL) err_sys("malloc error"); if ( (buf = malloc(BUF_SIZE)) == NULL) { err_sys("malloc error"); } tokens = (char **)malloc(sizeof(char *)); ++num_of_str; strcpy(html_buf, "keek oe aaf\r\npqrstu vwxyz\n"); strcpy(buf, strtok(html_buf, delimiters)); tokens[cnt] = malloc(strlen(buf)); strcpy(tokens[cnt], buf); printf ("%s\n",(tokens[cnt])); while (tokens[cnt] != NULL) { ++cnt; strcpy(buf, strtok(NULL, delimiters)); if( ( tokens = (char **)realloc((char **)tokens, (++num_of_str + sizeof(char *))) )== NULL ) err_sys("malloc error"); if( ( tokens[cnt] = malloc(strlen(buf)) ) == NULL ) err_sys("malloc error"); strcpy(tokens[cnt], buf); printf ("%s\n",(tokens[cnt])); } free(buf); exit(0); }