int spitString(char * buf1, char *c, char buf2[10][30], int *count )
{
int i = 0;
int len = 0;
char *temp1 = buf1;
char *temp2 = buf1;
while ((temp1 = strstr(temp2, c)) != NULL)
{
//temp1 = strstr(temp2, c);
len = temp1 - temp2;
memcpy(buf2[i++], temp2, len);
temp2 = temp1 + 1;
}
*count = i;
return 1;
}
void main
{
char *str = "aaaa,bbbb,cccc,dddd,";
char buf[10][30] = {0};
int count;
int i;
spitString(str, ",", buf, &count);
for (i=0; i<count; i++)
{
printf("%s\n",buf[i]);
}
printf("%d\n",count);
system("pause");
}
本人亲测有效,望共同学习进步。