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;
     }

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.

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

one two three you're hi
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

word\n
word2\t
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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.