Just count the number of newline characters ('\n') until the current read/write position.

Something like this (pseudocode):
Code:
int number_of_lines = 1;
for (i = 0; i < file_position; i++) {
    if (file_chars[i] == '\n') {
        number_of_lines++;
    }
}