String Tokernizer

Can anyone explain the difference between the following lines in the below program

p = strtok (string,",:");
p = strtok (NULL,",:");


program
=======

#include <stdio.h>
#include <string.h>
int main ()
{
char string[50] ="Test,string1,Test,string2:Test:string3";
char *p;
printf ("String \"%s\" is split into tokens:\n",string);
p = strtok (string,",:");
while (p!= NULL)
{
printf ("%s\n",p);
p = strtok (NULL, ",:");
}
return 0;
}
Last edited on
char *strtok( char *restrict str, const char *restrict delim );

If str != NULL, the call is treated as the first call to strtok for this particular string. The function searches for the first character which is not contained in delim.

If str == NULL, the call is treated as a subsequent calls to strtok: the function continues from where it left in previous invocation.

http://en.cppreference.com/w/c/string/byte/strtok
closed account (E0p9LyTq)
http://www.cplusplus.com/reference/cstring/strtok/
Thanks for your response. I got some idea now about strtok().
Topic archived. No new replies allowed.