View Single Post
  #2 (permalink)  
Old 10-23-2007, 12:54 PM
limo limo is offline
Newbie
 
Join Date: Oct 2007
Location: Australia
Posts: 14
Rep Power: 0
limo is on a distinguished road
Default

Here you go, comments added

HTML Code:
  char *local = strdup(tosplit); // makes a copy of tosplit, and 
  // returns a pointer to the allocated copy

    char *tok = strtok(local, delim); // split local into tokens using
    // delim, store the first token in tok

    int i = 0; // counter for token

    while(tok) { // while token is not null

        *parsed++ = strdup(tok); // makes a copy of token, 
        // returns a pointer to the allocated copy which is stored in 
        // parsed, parsed is then increment to point to the next 
        // pointer

        i++; // increment the number of tokens parsed

        tok = strtok(NULL, delim); // get next token

    }

    *len = i; // stores the number of tokens in len

    free(local); // frees the memory taken up local

// when the function returns, *parsed will contain tokens created from tosplit
Reply With Quote