- #include <stdlib.h>
-
#include <stdio.h>
-
#include <string.h>
-
#define OK 0
-
int main(int argc, char *argv[])
-
{
-
char *reg="abc*ab*pc*ac*xxxxxxxxxxxxx*b";
-
char * token;
-
printf("the pattern is %s\r\n",reg);
-
token=strtok(reg,"*");
-
while(token){
-
printf("result is %s\r\n",token);
-
token=strtok(NULL,"*");
-
}
-
printf("after the match ,the pattern is %s\r\n",reg);
-
getchar();
-
return OK;
-
}
usage char *strtok( char *str1, const char * ct );
A sequence of calls of strtok(s,ct) splits s into tokens,each delimited by a character from ct.
The first call in a sequence has a non-NULl s,it finds the first token in s consisting of characters not in ct;it terminates that by overwritting the next character of s with '\0' and return a pointer to the token.Each subsequence call,indicated by a NULL value of s,returns the next sush token,searching from just past the end of the previous one.strtok return NULL when no further token is found.The string ct may be different on each call
阅读(916) | 评论(0) | 转发(0) |