Okay, lets presume your file is text and that each line of text is terminated by a new line character.
open file to read text,
fp = fopen(filename, "rt"

;
then loop through each line of text and increment the counter like so
int counter = 0;
char str[line_length]; // string of required length
FILE *fp;
fp = fopen(filename, "rt"

;
while(fscanf(fp,"%[^\n]\n", str)!=EOF)
counter++;
printf("File holds %d lines of text", counter);
// this part of the code - "%[^\n]\n"- will read a string of characters up to the new line character - the extra \n then discards the new line character
OKAY
if file is binary file and you know the structure of each record.
struct myrecord {
// your structure members
};
int main (void)
{
FILE *fp;
int counter;
fp = fopen(filename, "rb"

;
fseek(fp, 0L, SEEK_END);
counter = ftell(fp)/ sizeof(struct myrecord);
printf("File holds %d lines of text", counter);
// remember to reset file pointer to start of file
// before carrying out further operations on the file
fseek(fp, 0L, SEEK_SET);
// remainder of your code for whatever you require
} //end main
Hoping to get certified..in C programming.