Solved

Input/Output

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

Independent Software Vendors: 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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

690 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