#include #include int main(void) { char *p; p = strtok("The summer soldier, the sunshine patriot", " "); printf(p); do { p = strtok('\0', ", "); if(p) printf("|%s", p); } while(p); return 0; } #include #include int main () { char str[] ="This is a sample string, just testing."; char *p; printf ("Split \"%s\" in tokens:\n", str); p = strtok (str," "); while (p != NULL) { printf ("%s\n", p); p = strtok (NULL, " ,"); } return 0; } char str[] = "now # is the time for all # good men to come to the # aid of their country"; char delims[] = "#"; char *result = NULL; result = strtok( str, delims ); while( result != NULL ) { printf( "result is \"%s\"\n", result ); result = strtok( NULL, delims ); } OUTPUT: result is "now " result is " is the time for all " result is " good men to come to the " result is " aid of their country" ######################################################### Syntax: #include char *strtok( char *str1, const char *str2 ); Description: The strtok() function returns a pointer to the next "token" in str1, where str2 contains the delimiters that determine the token. strtok() returns NULL if no token is found. In order to convert a string to tokens, the first call to strtok() should have str1 point to the string to be tokenized. All calls after this should have str1 be NULL. Example: char str[] = "now # is the time for all # good men to come to the # aid of their country"; char delims[] = "#"; char *result = NULL; result = strtok( str, delims ); while( result != NULL ) { printf( "result is \"%s\"\n", result ); result = strtok( NULL, delims ); } OUTPUT: result is "now " result is " is the time for all " result is " good men to come to the " result is " aid of their country" Related Topics: strchr(), strcspn(), strpbrk(), strrchr(), strspn() ----------------------------------------------------- Syntax: #include char *strchr( const char *str, int ch ); Description: The function strchr() returns a pointer to the first occurence of ch in str, or NULL if ch is not found. Related Topics: strpbrk(), strspn(), strstr(), strtok() ----------------------------------------------------- Syntax: #include size_t strcspn( const char *str1, const char *str2 ); Description: The function strcspn() returns the index of the first character in str1 that matches any of the characters in str2. Related Topics: strrchr(), strpbrk(), strstr(), strtok()