Character/Word Count From File

Hey. I tried to figure this out but I'm just not having making any progress. My class requires me to make a program that reads characters from a .txt file and state how many characters are in the file as well as how many words are in the file. I am able to correctly assess the amount of printed characters, but the amount of words continually tells me a different answer than it's supposed to be. Thanks for your help.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  int characterCountFunct(ifstream &input, int &wordCount)
{
	// Declares a variable which counts the amounts of characters
	int charCount = 0;

	// A variable that analyzes the characters passed through it from the document
	char character;

	// Declares a variable which counts the amount of words in the document
	// which is a reference variable manipulating a variable from the main function
	wordCount=0;

	// As long as the input has a character to analyze
	while (input.get(character))
	{

	// If the character being analyzed is NOT a new line, tab, return or empty space
		if (isspace(character))
		{

	// Then it must be a character, increase the count by one.
			wordCount++;
		}


	// Otherwise tell the user what issue is being found.
		else if (!isspace(character))
		{
			charCount++;
		}

		else if (input.eof())
		{
			wordCount++;
		}

	}

	return charCount;
}

Topic archived. No new replies allowed.