Question: Why is this loop stuck in an infinite loop? // Prime Read of First Character inFile.get(ch); while(inFile.good()) { // Line Count linecount = 0; linecount++;
Why is this loop stuck in an infinite loop?
// Prime Read of First Character
inFile.get(ch);
while(inFile.good())
{
// Line Count
linecount = 0;
linecount++;
letters = 0;
digits = 0;
other = 0;
while(ch != ' ')
{
// Letter Count
if(isalpha(ch))
letters++;
// Digit Count
else if(isdigit(ch))
digits++;
// Other Count
else //(!isalpha(ch) && !isdigit(ch));
other++;
inFile.get(ch);
}
// Total
linetotal = letters + digits + other;
other++;
cout << left << setw(15) << linecount << setw(10) << letters << setw(10) << digits <<
setw(10) << other << setw(10) << linetotal << endl;
// Totals for each Column
totallet += letters;
totaldig += digits;
totaloth += other;
totals = totallet + totaldig + totaloth;
// Percent
percentlet = (float)totallet / (float)totals;
percentdig = (float)totaldig / (float)totals;
percentoth = (float)totaloth / (float)totals;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
