Results 1 to 3 of 3

Thread: linked list help

  1. #1

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919

    linked list help

    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

    thanks :0
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    what error?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    nevermind i got it. access violation. i didnt allocate it properly
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width