#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char *p;
char buf[] = "abc,mike,yuantianxin,hello";
char tmp[100];
strcpy(tmp,buf);//分割会破坏原来的字符串,所以复制
//第一次调用
p = strtok(tmp,",");
while(p != NULL) {
printf("p = %s\n",p);
//第二次起,第一个参数需要写NULL
p = strtok(NULL, ",");
}
return 0;
}
#include <stdlib.h>
#include <string.h>
int main()
{
char *p;
char buf[] = "abc,mike,yuantianxin,hello";
char tmp[100];
strcpy(tmp,buf);//分割会破坏原来的字符串,所以复制
//第一次调用
p = strtok(tmp,",");
while(p != NULL) {
printf("p = %s\n",p);
//第二次起,第一个参数需要写NULL
p = strtok(NULL, ",");
}
return 0;
}