eg (1)
#include
#include
main()
{
char s[]="ab-cd : ef;gh :i-jkl;mnop;qrs-tu: vwx-y;z";
char *delim="-: ";
char *p;
printf("%s ",strtok(s,delim));
while((p=strtok(NULL,delim)))printf("%s ",p);
printf("\n");
}
输出结果为:
ab cd ef;gh i jkl;mnop;qrs tu vwx y;z
eg(2)
#include
#include
main()
{
char s[]="23123412345";
char *delim="1";
char *p;
printf("%s ",strtok(s,delim));
printf("%s ",strtok(NULL,delim));
printf("\n");
printf("%s ",strtok(NULL,delim));
printf("\n");
}
输出结果为:
23
234
2345
教训:(strtok这个函数害了花了很多时间才理解,在网上观看例子,有点抽象,最后还是把代码敲进去,检验了一下才明白.以后要多动手,光看不行)
阅读(783) | 评论(0) | 转发(0) |