/*-------------------------------------------------------------------*/ /* teststrtok.c */ /* Demonstrate the strtok() function. */ /*-------------------------------------------------------------------*/ #include #include const char* DELIMITERS = " :\n"; int main(void) /* Demonstrate the strtok() function. */ { char pcBuffer[] = " one: two :three:four five\n"; char *pcWord; pcWord = strtok(pcBuffer, DELIMITERS); while (pcWord != NULL) { printf("Token: %s\n", pcWord); /* Call strtok() with NULL as the first parameter to continue searching the previously given string. */ pcWord = strtok(NULL, DELIMITERS); } /* Note that strtok() corrupts the given string. */ printf("Original string: %s\n", pcBuffer); return 0; } /* Example execution: $ gcc -Wall -ansi -pedantic -o teststrtok teststrtok.c $ teststrtok Token: one Token: two Token: three Token: four Token: five Original string: one */