strtok????

can any one explain this?
i didnt understand clearly.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/* strtok example */
#include <stdio.h>
#include <string.h>

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;
}
What is it that you don't understand?

Did you run the program?

Line 10 will tokenize str based on the list of delimiters and return a pointer to the start of the string.

Line 11 loops until the trailing null pointer (end of string) is returned by strtok.

Line 14 advances pch to the next token.


Topic archived. No new replies allowed.