Chinaunix首页 | 论坛 | 博客
  • 博客访问: 117754
  • 博文数量: 38
  • 博客积分: 2015
  • 博客等级: 大尉
  • 技术积分: 405
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-26 17:19
文章分类

全部博文(38)

文章存档

2011年(4)

2010年(34)

我的朋友

分类: C/C++

2010-11-12 11:50:22

调用方式:char *strtok(char *str1,char *str2);  
功能说明:函数strtok()返回字符串str1中指向一个由str2所指定的字符或者字符串的分隔符的指针,当没有要返回的分隔符时,就返回一个空指针。  
   
   函数strtok()实际上修改了有str1指向的字符串。每次找到一个分隔符后,一个空(NULL)就被放到分隔符处,函数用这种方法来连续查找该字符串。  
   
  例子:  
  #include   
  #include   
   
  int main( int argc, char *argv[] )  
  {  
     char *p;  
     char str[100]="This is a test,and you can use it";  
     p = strtok(str," "); //注意,此时得到的   p为指向字符串:"This",即在第一个分隔符前面的字符串,即每次找到一个分隔符后,一个空(NULL)就被放到分隔符处,所以此时NULL指针指向后面的字符串:"is   a   test   ,and   you   can   use   it"。  
           
     printf("%s\n",p); //此时显示:This  
     do  
     {  
        p = strtok(NULL, ","); //NULL即为上面返回的指针,即字符串:"is a test ,and you can use it"。  
        if(p)  
           printf("|%s",p);  
     }while(p);    
         
     return 0;  
  }    
阅读(1159) | 评论(1) | 转发(0) |
0

上一篇:C++ Virtual详解

下一篇:管道理论

给主人留下些什么吧!~~

chinaunix网友2010-11-12 17:14:50

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com