C ftell()

The ftell() function returns the current file position of the specified stream. We can use ftell() function to get the total size of a file after moving file pointer at the end of file. We can use SEEK_END constant to move the file pointer at the end of file.

Syntax:

snippet
long int ftell(FILE *stream)

Example:

File: ftell.c

snippet
#include 
#include 
void main (){
   FILE *fp;
   int length;
   clrscr();
   fp = fopen("file.txt", "r");
   fseek(fp, 0, SEEK_END);

   length = ftell(fp);

   fclose(fp);
   printf("Size of file: %d bytes", length);
   getch();
}

Output:

Output
Size of file: 21 bytes
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +