/*-------------------------------------------------------------------*/ /* teststrtok.c */ /* Demonstrate the strtok function. */ /*-------------------------------------------------------------------*/ #include #include int main(void) /* Demonstrate the strtok function. */ { char pcBuffer[] = " one: two :three:four five\n"; char *pcWord; pcWord = strtok(pcBuffer, " :\n"); while (pcWord != NULL) { printf("Token: %s\n", pcWord); pcWord = strtok(NULL, " :\n"); } /* Note that strtok corrupts the original 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 */