How it works...
We will open the chosen file in read-only mode. If the file opens successfully, it will be pointed at by the file pointer fp. Next, we will find out the total number of lines in the file using the following formula:
total number of bytes used by the file/number of bytes used by one line
To know the total number of bytes used by the file, the file pointer will be positioned at the bottom of the file and we will invoke the ftell function. The ftell function finds the current location of the file pointer. Because the file pointer is at the end of the file, using this function will tell us the total number of bytes used by the file. To find the number of bytes used by one line, we will use the sizeof function. We will apply the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access