Hi!
I made this program to count characters:
Problem_0: The last character is counted twice no matter is it a character, newline, blank or tab.
Problem_1: When I try to read an ".odt"(OpenOffice writer file) I get + 200 characters.
Can anyone give me a hint on why does this happen?
I made this program to count characters:
Code:
int CharacterCount()
{
/* Local variables. */
using namespace std;
ifstream fin(TextSaved); /* Read from the file given in the "case WM_CREATE" .*/
/* Local variables. */
char ch;
iAll = c = Blanks = Tabs = NewLines = 0; /* Global variables need to be cleared. */
while(fin)
{
fin.get(ch); /* Get the next character from the file. */
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9'))/* If ch is "a to z" or "A to Z" or "0 to 9". */
c++;
else
if(ch== ' ')
Blanks++;
if (ch == '\t')
Tabs++;
if (ch == '\n')
NewLines++;
}
iAll = c + Blanks + Tabs + NewLines;
return '0';
}
Problem_1: When I try to read an ".odt"(OpenOffice writer file) I get + 200 characters.
Can anyone give me a hint on why does this happen?