BoBok2002 0 Junior Poster in Training

I am trying to build a binary search tree. The elements in my input file is printing, but with junk. The problem is with the sentinel in the while loop. I'm not sure of what else to try. I've tried:
while (infile)
while (count != 14 && infile.good())
while (strcmp(Str, sentinel) != 0)

But none of those are working. A sample of my input file is:
meel meet food copy home link hear seed read twig tree rain quiz push ride meel

And my current output file is:
copy food€'M hear homeÈ'M link meeth'M push quizp(M rainX(M read@(M ride seedø'M tree twig((M

Please help me figure out what is wrong. The code is below. Thanks.

void buildTree(TNODE *&Parent)
{
     char Str[5];
     TNODE *temp, *temp1, *newnode;
     int compVal;
     bool found;
     char sentinel[5];
     int count = 0;
     
     infile >> sentinel >> Str;
     
     Parent = NULL;
       
     while (strcmp(Str, sentinel) != 0)
     //while (count != 14 && infile.good())
     {
             //infile >> Str;
             
             newnode = new TNODE;
             strcpy(newnode -> dataStr, Str);
             newnode -> left = NULL;
             newnode -> right = NULL;
             
             if (Parent == NULL)
             {
                found = 0;
                Parent = newnode;
             }
            else
             {
                 temp = Parent;
                 
                 while (temp != NULL)
                 {
                       temp1 = temp;
                       
                       compVal = strcmp(temp -> dataStr, Str);

                       if(compVal == 0)
                       {
                               found = 1;
                               outfile << "The insert item is already in the list ";
                               outfile << endl;
                       }
                       
                       else if (compVal > 0)
                            temp = temp -> left;
                       else
                           temp = temp -> right;
                 }//end while loop
                 
                  compVal = strcmp(temp1 -> dataStr, Str);
                  
                 if (compVal > 0)
                    temp1 -> left = newnode;
                 else
                    temp1 -> right = newnode;
                    
             }// end else
            // count++;
             infile >> Str;
    }       
}//end buildTree
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.