Monday, December 21, 2009

strtok Example

Tokenizing at '*' and '/'

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


int
main() {
char *token;
char *lasts;
char buf[50] ;

strcpy(buf,"3/4/5/**6*7");
printf("ntokenizing %s with strtok_r():n", buf);

if ((token = strtok_r(buf, "*/", &lasts)) != NULL) {
printf("token = %sn", token);
while ((token = strtok_r(NULL, "*/", &lasts)) != NULL) {
printf("token = %sn", token);
}
}
}


OUTPUT:
tokenizing 3/4/5/**6*7 with strtok_r():
token = 3
token = 4
token = 5
token = 6
token = 7

No comments:

Post a Comment