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