C examples for string.h:strtok
function
<cstring> <string.h>
Split string into tokens
char * strtok ( char * str, const char * delimiters );
Parameter | Description |
---|---|
str | C string to be toknized. |
delimiters | C string containing the delimiter characters. |
If a token is found, a pointer to the beginning of the token.
Otherwise, a null pointer. A null pointer is always returned when the end of the string is reached.
#include <stdio.h> #include <string.h> int main ()//w ww. j a v a2 s . c o m { 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; }