C/C++ strtok函数

一、头文件:#include <string.h>


二、函数原型:char * strtok (char *str, const char * delimiters);


三、参数:str,待分割的c风格的字符串(c-string);delimiters,分割符字符串。



四、说明:

将字符串str分解成若干个单词,单词之间以delimiters字符串中的任一一个字符分割。第一次调用strtok时,str应该是一个c风格的字符串(c-string),随后的调用中,  str应该是一个NULL指针。



五、例子:

[cpp]  view plain copy
  1. /* strtok example */  
  2. #include <stdio.h>  
  3. #include <string.h>  
  4.   
  5. int main ()  
  6. {  
  7.   char str[] ="- This, a sample string.";  
  8.   char * pch;  
  9.   printf ("Splitting string \"%s\" into tokens:\n",str);  
  10.   pch = strtok (str," ,.-");  
  11.   while (pch != NULL)  
  12.   {  
  13.     printf ("%s\n",pch);  
  14.     pch = strtok (NULL, " ,.-");  
  15.   }  
  16.   return 0;  
  17. }  

Output:

[cpp]  view plain copy
  1. Splitting string "- This, a sample string." into tokens:  
  2. This  
  3. a  
  4. sample  
  5. string  


此文章来自于【http://blog.csdn.net/isgray/article/details/6852258】

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值