库函数 之 strtok

strtok函数的作用是分割字符串。
 
函数原型:
char *strtok(char *str1, char *str2);  
返回在参数1中用参数2进行分割得到的字符串。
 
这句话可能比较绕口,具体看例子,比较容易理解。
// strtok_test.c 
#include <string.h>
#include <stdio.h>

int main()
{
  char s[] = "Iloveyou";
  char *p;

  p = strtok(s, "o");

  do {
    printf("%s\n", p);
  } while(p = strtok(NULL, "o"));
  // must be NULL, if you want to get the next token spilt by 2nd parameter

  return 0;
}




posted @ 2011-12-15 21:02  __BSD__  阅读(166)  评论(0编辑  收藏  举报