#include<stdio.h>#include<string.h>#include<assert.h>intsplit(char*str,constchar*separator,char**words){char*pNext;int count =0;assert(str!=NULL);assert(separator!=NULL);
pNext =strtok(str,separator);//分解字符串str为一组字符串,separator为分隔符while(pNext!=NULL){*words++= pNext;++count;
pNext =strtok(NULL,separator);//仍然使用上次的标志符号的位置(存在静态变量中)开始继续找,直到找到下一个分隔符。反复以NULL做参数,找到输出所有的标志符号}return count;}intmain(){char str[]="how are you my bro";//用来接收返回数据的数组。这里的数组元素只要设置的比分割后的子字符串个数大就好了。char*words[20]={0};//分割后子字符串的个数int num =0;
num=split(str," ",words);int i=0;for(i=0;i<num;i++){printf("%s\n",words[i]);}return0;}