Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1788995
  • 博文数量: 335
  • 博客积分: 4690
  • 博客等级: 上校
  • 技术积分: 4341
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-08 21:38
个人简介

无聊之人--除了技术,还是技术,你懂得

文章分类

全部博文(335)

文章存档

2016年(29)

2015年(18)

2014年(7)

2013年(86)

2012年(90)

2011年(105)

分类: C/C++

2011-10-08 18:03:49

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #define OK 0
  5. int main(int argc, char *argv[])
  6. {
  7. char *reg="abc*ab*pc*ac*xxxxxxxxxxxxx*b";
  8. char * token;
  9. printf("the pattern is %s\r\n",reg);
  10. token=strtok(reg,"*");
  11. while(token){
  12. printf("result is %s\r\n",token);
  13. token=strtok(NULL,"*");
  14. }
  15. printf("after the match ,the pattern is %s\r\n",reg);
  16. getchar();
  17. return OK;
  18. }
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) |
给主人留下些什么吧!~~