Code:
struct BLOCK {
vector <string> say;
vector <string> resp;
int index;
BLOCK *next;
};
BLOCK *first;
BLOCK *curr;
int cAIBrain::GetWords(char *strWork, char type){
string temp;
int numwords=0;
BLOCK *insert = new BLOCK;
//clear the >, so then the words are left
for(int i=0;i<=strlen(strWork);i++){
if(*strWork=='>')
break;
*strWork++;
}
*strWork++; //clear the >
while(*strWork!='/'){
//next time change this with the delimiter chosen
//by the user, for now it is a |
if(*strWork=='|' || *strWork=='<'){
*strWork++;
if(type=='s') { //if its a say block, add it to the say
insert->say.push_back(temp);
} else if(type=='r'){ //if its a resp block, add it to resp
insert->resp.push_back(temp);
}
numwords+=1;
temp="";
} else {
temp += *strWork;
}
*strWork++; //move to next character
}
AddNode(insert);
return numwords;
}
void cAIBrain::AddNode(BLOCK *node) {
if(first==NULL){
first=node;
} else {
curr=first;
while(curr!=NULL){
curr=curr->next; //ERROR HERE!
}
curr=node;
curr->next = NULL;
}
}
I get an error in the "AddNode" function, that's the entire code. I think maybe my linked list implementation is off. I know its not optimized etc, I'm just trying to get it to work
i set first to NULL in the class initialization, but ahh i cant figure it out
thanks