Saturday, August 1, 2009

Use of strtok, an easy example.

NAME

     strtok, strtok_r -- string tokens   

LIBRARY

     Standard C Library (libc, -lc)   

SYNOPSIS

     #include <stdio.h>
     char *      strtok(char *restrict str, const char *restrict sep);

Example C Code

#include <stdio.h>
#include <string.h>

int main () {
char test[80], blah[80];
char *sep = "\\/:;=-";
char *word, *phrase, *brkt, *brkb;

strcpy(test, "This;is.a:test:of=the/string\\tokenizer-function.");

for (word = strtok(test, sep);word; word = strtok(NULL, sep)) {
printf("string is: %s\n", word);
}

return 0;
}

No comments:

Post a Comment