Monday, July 9, 2018

C ftell() function

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:





long int ftell(FILE *stream)



Example:

File: 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("Size of file: %d bytes", length);
getch();
}



Output:

Size of file: 21 bytes




Instagram



No comments:

Post a Comment