First time posting a question. Seeking debugging help. I am trying to figure out where my logic is wrong in a c++11 function. The goal is to search for a given character in a file and record the number words it is in, the number of lines it is in, and the number of times it appears in the file in total. Lines and total amount of occurrences are accurate but the word count is off which I assume is because of my logic. lwc is a class I created and has int set methods. Where am I going wrong to properly count the amount of words that has a specific character in it? Thanks for your time.
void findChar(lwc *CH, string File)
{
ifstream file(File);
int a=0;
int b=0;
int c=0;
string line;
bool i = false;
bool j = false;
char ch;
while (!file.eof())
{
getline(file, line);
for (int g=0; g<line.length(); g++)
{ ch = line[g];
if (ch == CH->getChar()) //to count characters
{a++; i= true; j = true;}
if (isspace(ch) && j) //to count words
{c++; j=false;}
}
if (i) //to count lines
{b++; i = false;}
}
CH->setWords(c);
CH->setChars(a);
CH->setLines(b);
}