Link to home
Start Free TrialLog in
Avatar of John500
John500Flag for United States of America

asked on

Input/Output

To Todd, if (available)

I'm trying to read a file into a tree which holds words only.  The tree places these words in dictionary order through out the tree.

When reading in a file I want to use all non letter characters as delimiters for the strtok function to use as such:

char delim[] = " \n\t`~1!2@3#4$5%6^7&8*9(0)-_=+[{]}\|;:'\",<.>/?";
char *token;

if((token = strtok(buff, delim))!=0)
strlwr(token);
insertWord(token);

My questions are:

1.  Am I declaring white space properly in delim[], it's the first char I define by simply pressing the space bar.

2.  Since I don't want any leading white space before words do I need a stripper routine to eliminate spaces, shouldn't the above routine do the trick for that?

3.  As it stands now, the reading of the file into the tree works ok, but I notice it is missing some words.  I feel it may be due to the way I've declared a carriage return in delim [].  Has it been declared correctly (\n) and do you notice any character I'm forgetting in delim[]?

Thanks!

ASKER CERTIFIED SOLUTION
Avatar of sganta
sganta

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of John500

ASKER

Hey sganta,

The new delim[] you gave me cleared up a lot of problems.  When I stepped through the file, line by line, to see if all the words are being added, I noticed that a few different words get into the tree but not in the order I expected.  One word in particular is "initialize."  I tried to insert a little code to see what the count is of that word but its not working.  Any suggestions on the routine below.  I am sure that the counter is working properly because I've printed all the counts out but I want a routine where I can choose certain words - less work on the eyes during the printout.

char initialize;
char *q = &initialize;
    if(strcmp(p->_word,q)==0)
      {cout<<p->_word<<" "<<p->_count<<"\n";
       return;}

>JESUS LOVES YOU - This is true
Avatar of nietod
nietod

    char *q ="initialize";
         if(strcmp(p->_word,q)==0)
     {cout<<p->_word<<" "<<p->_count<<"\n";
     return;}

or

         if(strcmp(p->_word,"initialize")==0)
     {cout<<p->_word<<" "<<p->_count<<"\n";
     return;}
Hai John !

I 've seen your comment, But one thing I did'nt understand what you are doing here
char initialize; /* What is the value you are assigning to initialize */
      char *q = &initialize; /* Here you are assigning the initialize, but where is the value
                                       of q which is not assigned */
          if(strcmp(p->_word,q)==0)
      {cout<<p->_word<<" "<<p->_count<<"\n";
      return;}

------- If you want to compare with "initialize" word then do the following code.
      char *q = "initialize";
          if(strcmp(p->_word,q)==0)
      {cout<<p->_word<<" "<<p->_count<<"\n";
      return;}

If not , Can you explain me what exactly you want ?, with the code example written by you.
If you don't want to hide your code to others, Then send it to my EMail
sganta@ch.oracle.com
I hope I will be able to help you. Thank you.
The Grace of Lord will always be with us.
Hai John !
That's what I have mentioned in my earlier comment
char *q = "initialize";
  if(strcmp(p->_word,q)==0)
            {cout<<p->_word<<" "<<p->_count<<"\n";
            return;}