/* strtokex.c : PUBLIC DOMAIN - Jon Mayo - November 26, 2006 * - You may remove any comments you wish, modify this code any way you wish, * and distribute any way you wish. */ /* example of using strtok() function */ #include #include #include void process(FILE *in, const char *filename) { static const char *whitespace = " \t\n"; char buf[2048]; char *tok; int line; int i; for(line=1;fgets(buf, sizeof buf, in);line++) { for(i=0,tok=strtok(buf, whitespace);tok;i++,tok=strtok(0, whitespace)) { printf("%s:%d:%d:\"%s\"\n", filename, line, i, tok); } } } int main(int argc, char **argv) { if(argc<2) { process(stdin, "stdin"); } else { int i; FILE *in; for(i=1;i