ftell() in C programming

File Handling: ftell() in C programming

File Handling in C programming helps us to perform multiple functions such as read,create or update any file which is stored on our local system using C Language.File handling helps to eliminate the problem of handling and displaying large amount of data.In this section, we will learn the ftell() function of file handling in C programming.
ftell() in C programming

ftell() function in C programming:

ftell() function in file handling in C language is used to determine the position of the file pointer inside the file in reference to the starting of the file. This function helps to identify the file pointer location so that we can perform the next operations with ease. This function is of great use as a user while performing multiple functions could not have kept track of the file pointer’s position.

Syntax of ftell() :

long int ftell(FILE *stream)

There is only one parameter used in the syntax which is mentioned below:

  • Stream- It is used to point to the File object that helps to find the stream in which data is to be written.

NOTE  :  The ftell() command in C programming returns the location of the file pointer in long data type.

Example 1:


void main () {
   FILE *f;
   int len;
   f = fopen("pqr.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

Example 2:

int main()
    FILE *fp = fopen("pqr.txt","r");
    char string[20];  
    printf("%ld", ftell(fp));
    return 0;



Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription