EmbLogic's Blog

Doubt:

What does strtok do? And how do we use it? I tried reading the man pages and tried some examples too but i m still unable to get the satisfactory explanation.

2 Responses to Doubt:

  1. msiddarth says:

    strtok() will replace a the characters in the original string with a NULL each time the function is called using the same string, so the original string is modified by the use of strtok().
    The second argument to strtok() can be changed at any time to a different delimiter.
    Only single characters are considered to be delimiters.
    The below example will illustrates the usage of strtok.
    #include
    #include

    int main()
    {
    const char str[80] = “This is – http://www.emblogic.com – website”;
    const char s[2] = “-”;
    char *token;

    /* get the first token */
    token = strtok(str, s);

    /* walk through other tokens */
    while( token != NULL )
    {
    printf( ” %s\n”, token );

    token = strtok(NULL, s);
    }

    return(0);
    }

    the output of the above program will be:
    This is
    http://www.tutorialspoint.com
    website

Leave a Reply to taruna Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>