函数原型:char *strtok(char *s, char *delim)
功能:strtok 在s中查找delim中的所有的字符并用“\0”来代替,直到找遍整个字符串。s为要分割的字符串,delim为分隔符字符串。
返回值:从s开头开始的一个个被分割的字符串,当没有分割的字符串时返回NULL。
说明:首次调用的时候,传进的第一个参数是要分割的字符串,此后调用,传进的第一个参数是NULL。
#include "stdio.h"
#include "string.h"
int main(int argc, char **argv)
{
char s[]="aaaaa, ,bd/ccc";
char delim[]= ",/";
char *result;
result = strtok(s, delim);
while(result != NULL)
{
printf("%s \n", result);
result = strtok(NULL, delim);
}
return 0;
}
输出结果为:
aaaaa
bd
ccc