Thread: BST addword function

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    11

    BST addword function *edited*

    Hi!
    I'm building a Tree that reads words in from a text file and adds it to the tree in sibling or child branches. Everything is being scanned in ok, but something is wrong with Addaword. It seems to not be getting past the first word of the array, and just winds up repeating it. Does anyone know how I would increment it correctly?

    *added more code to clarify*
    Code:
    class Node     
    {
       private:
       Node *sibling;
       Node *child;
       int occurs;
       int letters;
    
       public:
       AddAWord(char word[], int i);
       Search(char request[]);
       Node(char l) {occurs=0; sibling=0; child=0; letters=l;}
    };
    
    void main(void)
    {        
            Node *root=new Node('-');
            Node* new_node;
            char* word[80];
            int len;
            FILE*input;
            char* request[10];
            char str[80];
            int i = 0, k=0, l=0;
            ifstream b_file("abook.txt", ios::in);
    
                    b_file>>str;
                    for(int j=0; j < strlen(str); j++)
                    {
                            str[j] = tolower((int)str[j]); 
    			}
                   len = strlen(str);
                    word[i] = new (char[len+1]);
    
                   strcpy(word[i++], str);
                    root->AddAWord(*word, l);
           while(b_file.eof()==0 || i<80)
            {
                    b_file>>str;
                    for(int j=0; j < strlen(str); j++)
                    {                                   
    					str[j] = tolower((int)str[j]);
                    }
                    len = strlen(str);
                    word[i] = new (char[len+1]);
                    strcpy(word[i++], str);
                    new_node->AddAWord(word[i], l);
            }
            cout<<"What word would you like to search for: "<<endl;
            cin>>str;
            len = strlen(str);            
      request[k] = new (char[len+1]);
            strcpy(request[k++], str);
    }
    {
     cout<<word;
    
      if(letters!=word[0])
      {
        if(sibling==0)
        {               
     sibling=new Node(*word);
              i++;
          sibling->AddAWord(word, i);
        }
            else
            {
                    sibling->AddAWord(word, i++);
            }
      }
      else if(word[i] != '\0')
      {
              if(child == 0)
              {           
    child=new Node(*word);
                      printf("%c", word[i]);
                      i++;
                      child->AddAWord(word, i);
              }
             else
             {
                      child->AddAWord(word, i++);
            }
    }
    }
    Last edited by raell; 12-14-2003 at 09:52 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM