I need to create a method that counts words and lines using specific guidelines and I can't figure it out:
Update the count of words & lines in the file as each character is read
create a void method, CountIt(), to count the lines and words
Parameters: pass in the character by value
pass in a reference to the word count
pass in a reference to the line count
pass in a reference to the bool that tracks if you are "in a word"
Will need a bool variable to keep track WHEN you are IN A WORD or NOT.
bool inWord = true;
int linecount = 0, wordcount = 0;
.
.
.
// calling the CountIt() method (which is in a loop)
CountIt(x, ref linecount, ref wordcount, ref inWord);
.
.
.
// the CountIt() method
private static void CountIt(string x, ref int linecount, ref int wordcount, ref bool inWord)
{
//count words and lines in here.
}
I have no clue how to go about this (what the bool should say, what should be in my method). I've been trying to teach myself through reading and other means but no luck.