Solved

Input/Output

Posted on 1998-05-29
5
197 Views
Last Modified: 2012-05-04
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!

0
Comment
Question by:John500
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 4

Accepted Solution

by:
sganta earned 40 total points
ID: 1164933
Hai John !
? mark should be identified by using \?
\ mark should be identified by using \\
/mark should be identified by using \/
So delim should be
char delim[] = " \n\t`~1!2@3#4$5%6^7&8*9(0)-_=+[{]}|;:'\",<.>\/\\\?";

Try using this, I hope this will work for you.
JESUS LOVES YOU - sganta
0
 

Author Comment

by:John500
ID: 1164934
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
0
 
LVL 22

Expert Comment

by:nietod
ID: 1164935
    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;}
0
 
LVL 4

Expert Comment

by:sganta
ID: 1164936
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.
0
 
LVL 4

Expert Comment

by:sganta
ID: 1164937
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;}
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question