C Program Example strtok function
- #include <stdio.h>
- #include <stdlib.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," ,.-");
- if(pch == NULL) return -1; /* nedostatek pameti */
- while (pch != NULL)
- {
- printf ("%s\n",pch);
- free(pch);
- pch = strtok (NULL, " ,.-");
- if(pch == NULL) return -1;
- }
- free(pch);
- return 0;
- }