C++:
#include<iostream>
using namespace std;
/**
*有一个字符串符合以下特征("abcdef,acccd,eeee,aaaa,e3eeeee,sssss,";),要求写一个函数,输出以下结果
*1)以逗号分隔字符串,形成二维数组,并把结果传出
*2)把二维数组行数运算结果也传出
**/
void spitString(const char* buf1, const char c, char buf[10][30], int *mycount)
{
char *p = NULL; //
int count = 0;
int tmpcount = 0;
char *pTmp = NULL; //
char buf2[1024];
pTmp = (char *)buf1;
p = (char *)buf1;
do
{
p = strchr(p, c);
if (p != NULL) //如果找到
{
tmpcount = p - pTmp;
memcpy(buf[count], pTmp, tmpcount); //从pTmp复制tmpcount个字符到buf
buf[count][tmpcount] = '\0';
printf("%s\n", buf[count]);
pTmp = p = p + 1;
count++;
}
else
{
break;
}
} while (*p != '\0');
}
void main()
{
char* p = "abcdef,acccd,eeee,aaaa,e3eeeee,sssss,";
char c = ',';
char buf[10][30];
int ncount;
spitString(p, c, buf, &ncount);
system("pause");
}