Okay I have code that is supposed to get a number of words in a text file....for some reason it will half of the number of words in the text file....There are actually 6338 words in this text file...I only come up with exactly half which is 3169...I don't see anything wrong with the code so maybe you guys can figure it out
Code:
void CountNumberOfWordsAndNumberOfCharacter()
//Pre:Get Number of Words and Number of characters in Text file
//Post:Output Number of Words and Number of Characters
{
int Choice = 0;
apstring Words;
long int TotalWords = 0;
char Characters;
long int TotalCharacters = 0;
cout << endl;
cout << "Enter your choice count number of words and characters" << endl;
cout << endl;
cout << "[1] Words.txt" << endl << endl;
cout << "[2] melville.txt" << endl << endl;
cout << "[3] caesar.txt" << endl << endl;
cin >> Choice;
while(Choice != 1 && Choice != 2 && Choice != 3)
{
cout << "Input Error, please choose again." << endl;
cin >> Choice;
}
switch(Choice)
{
case 1:
{
ifstream instream("C:\\STR\\words.txt");
while(instream>>Words)
{
TotalWords++;
}
while(instream>>Characters)
{
TotalCharacters++;
}
cout << "Total Amount Of Words : " << TotalWords << endl;
cout << "Total Amount of Characters : " << TotalCharacters << endl;
break;
}
}
}