Thread: Doubt about strtok function

  1. #1
    Registered User
    Join Date
    Apr 2011
    Location
    Bangalore
    Posts
    20

    Doubt about strtok function

    Hi all,

    Can anybody help me to understand the working of strtok function.
    I write a small program and it's give some output that i am unable to understand.
    Code:
    #include<stdio.h>
    #include<string.h>
    int main()
    {
    	char* temp1;
    	char* temp = _strdup("hi,,ji,ki,ko,f,,s,,");
    	temp1 = strtok(temp,",,");
    	while(temp1)
    	{
    		printf("%s\n",temp1);
    		temp1 = strtok(NULL,",,");
    	}
    	return 1;
    }
    The output i got is
    hi
    ji
    ko
    f
    s

    I am using visual studio 2010.

    Thanks

  2. #2
    Registered User
    Join Date
    Nov 2011
    Location
    Saratoga, California, USA
    Posts
    334
    It appears that you believe that strtok will use ,, as a delimiter and ignore ,

    That is not the case - strtok will match to ANY characters in const char *delimiters.

    So, for ",;:-", strtok will consider ',' ';' ':' and '-' as delimiters.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strtok function
    By Omnipotent in forum C Programming
    Replies: 7
    Last Post: 04-03-2011, 08:12 PM
  2. Problem with STRTOK function
    By dardar in forum C Programming
    Replies: 19
    Last Post: 10-17-2010, 01:27 PM
  3. Function-doubt
    By fluteofliar in forum C Programming
    Replies: 9
    Last Post: 06-07-2010, 08:17 AM
  4. memory and strtok function!!
    By Leojeen in forum C Programming
    Replies: 5
    Last Post: 05-25-2008, 02:53 AM
  5. strtok function
    By hello124 in forum C++ Programming
    Replies: 8
    Last Post: 04-23-2005, 06:58 AM