对字符串分割后比较
得到“1,2354,7985,9895;2,4674,4874,49455;3,17434,4687,46875”这样的一个字符串格式是“编号1,数据a,数据b,数据c;编号2,数据a,数据b,数据c;编号3,数据a,数据b,数据c”
分别比较编号123的a数据,b数据,c数据。
如何实现。。。
我的想法声明一个char* array[3][4],arrary[0][0]指向编号1,array[0][1]指向编号1的数据a,array[0][2]指向数据b;依次类推。。。。
但是被自己绕晕了。。
程序代码:#include<iostream>
#include<stdlib.h>
#include<string>
#include<string.h>
using namespace std;
int main()
{
std::string const str00="1,1234,9678,2;2,3584,6842,1;3,8527,5746,3";
std::string const &cellsInfo=str00;//以上是模拟的接口
char *point=(char*)malloc(cellsInfo.length());
//point=strcpy(point,cellsInfo); //strcpy为什么不能用
int length=0;
for(;length<cellsInfo.length();length++)
{
point[length]=cellsInfo[length];
}
char* array[3][4];
int m,n=0;
int index=1;
for(length=0;length<cellsInfo.length();length++,index++)
{
cout<<"length="<<length<<" index="<<index<<" m="<<m<<" n="<<n;
cout<<" cellsInfo["<<length<<"]="<<cellsInfo[length]<<" point["<<index<<"]="<<point[index]<<endl;
if(cellsInfo[length]==',')
{
point[index-1]='\0';//试图用移动指针来分割字符串。
array[m][n]=point;
n++;index=0;
for(int i=1;i<index;i++)
{
point++;
}//在移动指针的时候出现了问题
}
if(cellsInfo[length]==';')//下面肯定是不对啊
{
point[index-1]='\0';
array[m][n]=point;
m++;n=0;point++;index=0;
}
}
while(m--)
{
while(n--)
{
free(array[m][n]);
}
}
free(point);
return 0;
}


