1 /* 2 Title:strtok.c 3 Author:Dojking 4 */ 5 #include <stdio.h> 6 #include <string.h> 7 8 int main() 9 { 10 char strToken[] = "This is my blog"; 11 char strDelimit[] = " "; 12 char *tok; 13 14 for (tok = strtok(strToken, strDelimit); tok != NULL; tok = strtok(NULL, strDelimit)) 15 puts(tok); 16 17 return 0; 18 }
This
is
my
blog
--------------------------------
Process exited with return value
0
Press any key to continue . . .
多个分隔符测试:
1 /* 2 Title:strtok.c 3 Author:Dojking 4 */ 5 #include <stdio.h> 6 #include <string.h> 7 8 int main() 9 { 10 char strToken[] = "This,is my+blog"; 11 char strDelimit[] = ", +"; 12 char *tok; 13 14 for (tok = strtok(strToken, strDelimit); tok != NULL; tok = strtok(NULL, strDelimit)) 15 puts(tok); 16 17 return 0; 18 }
输出结果:
This
is
my
blog
--------------------------------
Process exited with return value
0
Press any key to continue . . .
推荐一篇讲得详细的文章,liuintermilan的专栏,http://blog.csdn.net/liuintermilan/article/details/6280816
原文:http://www.cnblogs.com/jopus/p/3623801.html