ftell() in C

CProgrammingServer Side Programming

In C language, ftell() returns the current file position of the specified stream with respect to the starting of the file. This function is used to get the total size of file after moving the file pointer at the end of the file. It returns the current position in long type and file can have more than 32767 bytes of data.

Here is the syntax of ftell() in C language,

long int ftell(FILE *stream)

Here is the parameter used in ftell(),

  • stream − This is the pointer to a FILE object that identifies the stream.

Here is an example of ftell() in C language.

Let’s say we have a file “one.txt” with the following content.

This is demo text!
This is demo text!
This is demo text!

Now, let us see the example.


#include <stdio.h>
void main () {
   FILE *f;
   int len;
   f = fopen("one.txt", "r");
   if(f == NULL) {
      perror(“Error opening file”);
   fseek(f, 0, SEEK_END);
   len = ftell(f);
   printf("Size of file: %d bytes", len);


Size of file: 78 bytes
Updated on 24-Jun-2020 11:00:53