here's the code:
and thx a lot for ur help!
u'll notice i've followed ur advice:)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
//explanations after the code
void Assign(int q,int r,char* str,Node** N,int& I)
{
static NumNode* C=new NumNode[MAX];
static int k=0;
if((r-q)>1)
{
char *sss=new char[r-q-1];
for(int i=q+1;i<r;i++)
sss[i-(q+1)]=str[i];
double x=strtoul(sss,NULL,10);
NumNode nun(x);
C[k]=nun;
N[I]=&C[k];k++;
I++;
}
}
|
so about the code:
Assign(int q,int r,char*str,Node**,int &i)
q and r are indices refering to characters in the string,
N is an array of pointers to objects from a class called Node,
i just stores the lenght of N.
two classes inherit from Node,called NumNode and OpNode.
for example:
Assign(1,4,str,N,i) where str="1+23-4"
will parse the string from str[1+1] to str[4-1]
in search of an integer value,then store it in a NumNode,wich is
a class derived from a base class called Node.
now as i said before it works fine most of the time,but if i run it multiple times in a row,
it'll return nonsense once or twice before working properly again.
thx a lot for ur help and patience.