Hi all,
My code for a function to count words is posted below, and the only error that appears when I build it in my compiler is that char present is uninitialized. My program will not run with this uninitialized value. I've been searching for info on how to initialize my char present but have come up empty. The closest I've come is thinking that I may need to use a char pointer, but I'm not sure how to apply it in the context of this function. Any help is greatly appreciated.
Thanks.
int countWords(ifstream& fileName)
{
int wordCount=0;
char present;
char next;
fileName.get(next);
while (!fileName.eof())
{
if((!isspace(present) && (present != '.') && (present != ',')) && (isspace(next) || (next == '.') || (next == ',')))
{
wordCount++;
}
present = next;
fileName.get(next);
}
return wordCount;
}