Your version outputs the size of the file in a non-portable way. For example, on Windows with a file that uses CRLF as newlines, your code will count one less byte for each newline in the file.
The original code also sucks for a similar reason.
This is how I would do it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
//At this point, the file has already been read onto memory, but I don't feel
//like writing that part.
long l=/*size of the file in memory*/;
char buffer=/*file buffer*/;
long lines=0;
for (long a=0;a<l;a++){
if (buffer[a]==10)
lines++;
elseif (buffer[a]==13){
lines++;
if (buffer[a+1]==10)
a++;
}
}
//lines contains the lines count.