Hey guys I am just wondering why the following code gives the wrong number of characters from a file when the character count is the default? Thanks.
void main()
{
int blank_count = 0;
int char_count = 0;
int sentence_count = 0;
char ch;
ifstream iFile("c:\test.txt");
if (! iFile)
{
cout << "Error opening input file" << endl;
}
while (iFile.get(ch))
{
switch (ch) {
case ' ':
blank_count++;
break;
case '.':
sentence_count++;
break;
default:
char_count++;
break;
}
}
cout << "There are " << blank_count << " blanks" << endl;
cout << "There are " << char_count << " characters" << endl;
cout << "There are " << sentence_count << " sentences" << endl;
}