My goal is to read from an input file and count the number of lines that have at least 1 lowercase letter and 1 digit. I have already solved the rest of my code which counted all of the lowercase, uppercase, digits, characters and words no problem. I have also read from the input file and reversed the lines word by word. I cannot seem to figure out why the code is counting 8 lines when there are only 7 with 1 lowercase and 1 digit. While using getline() for all of the other loops, I've had no issues. I'm not looking specifically for someone to write the code for me. I'd just like an explanation of why this is happening if possible?
My input file contains:
This is a test file for hw3
How many Uppercase letters are in this f1le?
How many Lowercase letters are in this F1le?
H0W mAnY dIg1ts ar3 1N in this FILe?
Turn the 1npU7 N4m3 int0 its reverse
reverse the Lines to their opp05173 coutnerpart
find tOTal NumbEr of characTer5 in F1le
THIS IS A TEST LINE
My code for this section is:
inFile.clear();
inFile.seekg(0, inFile.beg);
while(getline(inFile, line)){
wordInput.str(line);
wordInput.clear();
wordInput.seekg(0);
while(wordInput.get(c)){
if(islower(c)){
lowerCase++;
}
else if(isdigit(c)){
digit++;
}
}
if(lowerCase >= 1 && digit >= 1){
lineCount++;
}
}
cout << lineCount << endl;
return 0;
}
I have initialized all of my int variables to 0 and the top and I have declared my sstream variables as well. My libraries include <sstream>
<fstream>
<string>
<iostream>
and <algorithm>
(which was used for earlier parts.
The output I am getting is
8
when it should be 7. The final line should not be counted as it has no lowercase letters and no digits. I am thinking that the first line is being read a second time and then stopping. I am in an intro to C++ class and have yet to learn how to use the debugger. Thank you in advance.