Quote Originally Posted by dwks
Yes, fgets() returns NULL if no characters were stored in the string before EOF was encountered.

This code:
Code:
while(fgets(line, sizeof(line), fp)) count ++;
is better than just counting newlines, because you can have a line in a file that isn't terminated by a newline. That is, if you have a file with the contents "foo", the fgets() method will claim the file has one line (which is probably what you want), whereas just counting the newlines would give you zero lines.
True but what happens if the line exceeds the array limits? It would continue to pull in data until it reached the new-line character each time doing a call to fgets and incrementing the counter each time as well?