Strtok
char* strtok(char *str, char *delimitter)
{
    static char *state;   // state is a char pointer point to a specific char
    // location in "str". It records non-scanned part 
    char *d, *beg;
    if (str != NULL)
        state = str;
    for (; *state != '\0'; state++) {   // find beg, delete previous delimitter 
        for (d = delimitter; *d != '\0'; d++)
            if (*d == *state)
                break;
        if (*d == '\0')
            break;
    }
    if (*state == '\0')    // if reach '\0', no token, return NULL
        return NULL;
    else
        beg = state;       // else, find beg
 
    for (; *state != '\0'; state++) {   // find end
        for (d= delimitter; *d != '\0'; d++)
            if (*d == *state)
                break;
        if (*d != '\0')
            break;
    }
    if (*state != '\0')     // if not reach '\0', put '\0', and state++
        *state++ = '\0';
 
    return beg;    // return beg of token
}
 
int main ()
{
    char str[] ="- This, a sample string.";
    char *pch;
    printf ("Splitting string \"%s\" into tokens:\n",str);
    pch = strtok(str, " ,.-");
    while (pch != NULL) {
        printf("%s\n", pch);
        pch = strtok(NULL, " ,.-");
    }
    return 0;
}

Output:

Splitting string "- This, a sample string." into tokens:
This
a
sample
string

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License