English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structure

C Language File

C Others

C Language Reference Manual

C File ftell() Function

The ftell() function returns the current file position of the specified stream. After moving the file pointer to the end of the file, we can use the ftell() function to obtain the total size of the file. We can move the file pointer to the end of the file using the SEEK_END constant.

Syntax:

long int ftell(FILE *stream)

Program: ftell.c

#include <stdio.h>  
#include <conio.h>  
void main (){  
   FILE *fp;  
   int length;  
   clrscr();  
   fp = fopen("file.txt", "r");  
   fseek(fp, 0, SEEK_END);  
  
   length = ftell(fp);  
  
   fclose(fp);  
   printf("File Size: %d bytes", length);  
   getch();  
}

Output:

File Size: 21 bytes