Comparisons

Reply

Join Date: Apr 2008
Posts: 185
Reputation: DemonGal711 is an unknown quantity at this point 
Solved Threads: 10
DemonGal711 DemonGal711 is offline Offline
Junior Poster

Comparisons

 
0
  #1
Dec 2nd, 2008
I have to read in values from a file and output only the ones that past the test. However, I'm not sure how to compare a few of them.

I need to skip the word if it ends with '\n', '\t', or a space. So, how exactly would you handle and test for this. I have the rest down path, just these three are giving me issues. He didn't tell us what the input file would look like, so I'm assuming it's one line has one word on it, so that's what I coded for. But then that leads to the problem that all the lines end with the \n char, hence my dilemma.

Any suggestions of what to do?

This code works so far, but it doesn't do anything if it ends in the last three bad[] chars.
char bad[20] = {'{', '[', '(', '"', '‘', ',', '.', '?', ';', ':', '%', '@', '-', '}', ']', ')', '`', ' ', '\n', '\t'};

main ()
{   BST A;
    string n;
    int max = 0, x = 0;
    ifstream In;
    getFile (In);
	while (getline(In, n))
		  { cout << n << endl;
            if (check(n, x) == true)
	           { max = (max>=x) ? max : x;
                 for (int i = 0; i < n.length(); i++)
                     { n[i] = tolower(n[i]); }
                       A.Insert(n); } }
    cout << setw(max) << "Word" << "\tOccurance\n";
    A.Print(max);
    
    system("pause");
	return 0;
}
     
bool check (string word, int& size)
     {  size = word.length();
        string n;
        for (int i = 0; i < 17; i++)
            { if (word[size] == bad[i]) return false; 
              n = word[size-2] + word[size-1];
              if (n == bad2[0] || n == bad2[1] || n == bad2[2]) return false; }
        for (int x = 0; x < 5; x++)
            { if (word[0] == bad[x]) return false; }
        return true;
     }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,170
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1439
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Comparisons

 
0
  #2
Dec 2nd, 2008
Every line in a text file ends with '\n'. According to your instructions you would have to skip the last word of every line that is read. Lines do not have embedded '\n' characters.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 185
Reputation: DemonGal711 is an unknown quantity at this point 
Solved Threads: 10
DemonGal711 DemonGal711 is offline Offline
Junior Poster

Re: Comparisons

 
0
  #3
Dec 2nd, 2008
Yeah, so I'm not entirely sure how to handle the coding for this. I mean, I'm basically done, I just don't know what to use as a test. If the input file looks like this
  1. one two three you're hi
  2. these they're abc.com one
Then basically all the words should drop out cause they all either end with a space or a newline character, even though they aren't on the word technically. But, if you think of the space as a separator, then there's the issue that how would you determine if a character ends with a space. Then there is also the factor of how do you determine if it ends with a \t or \n character as well. The only way I can figure is that it's hard coded in, like
  1. word\n
  2. word2\t
  3. word3 // this one ends in a space
But, if that's the case, it seems a little he would have told us that or something. I just don't know which one to code for.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC