Hey Guys,
So, I am writing a program that reads in from a file, and prints the word and counts the number of lines in the document. Here is the function that is supposed to do the work. Every time I run it lineCount is always 0.
string getString(ifstream& inFile, int &lineCount)
{
char letter;
string letters = "";
inFile.get(letter);
if(letter == '\n')
lineCount++;
while(inFile && !isalnum(letter))
{
if(letter == '\n')
{
lineCount++;
}
inFile.get(letter);
}
if (!inFile)
return letters;
else
{
do
{
letter = tolower(letter);
letters = letters + letter;
inFile.get(letter);
}while (isalnum(letter) && inFile);
return letters;
}
}