File Line Count

Hi,
Came across a weird problem today.
I was just trying to write this small script which would read the number of lines in a file. Depending on the count some further processing would be done. I used wc -l in order to get that done.
But since it depends on the number of new line characters, if the file did not end with a new line character it was returning a count that was less by 1.
And when I just pressed an enter key in vi editor at the end of the last line and ran the wc -l command again it returned me a count greater than the actual number of lines in the file by 1 !!!
So if the file has got 3 lines in it, then wc -l gives me a count of 2 if there is no newline character at the end of the file.
And it gives an o/p of 4 if I press an enter at the end of the file.
My questions are:
1) Why am I getting 4 in the latter case?
2) How can I get the exact line count?
Thanks in advance.

I'm not sure about this, but vi may have an option to automatically add a newline at the end of each line.

So, if a file has 3 lines with no newline at the end of the 3d line, pressing enter would add a new line on the third line, and create a new line containing just a newline, hence 4 lines in total.

For me, opening a file with vi and just saving it (without doing any modification) seems to do what you want.