Solved

Input/Output

Posted on 1998-05-29
5
167 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
  • 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now