ftell function in c

ftell() function in c

Declaration:
long ftell(FILE *fptr);

This function ftell(FILE *fptr) returns the current position of the file position indicator. so the value is count from the beginning of the file.

/* program to understand the use of ftell() */
#include<stdio.h>
#include<stdlib.h>
struct
Employee
{
int empid;
char name[30];
float salary;
}emp;
int main()
{
FILE *fptr;
fptr=fopen("myfile","rb");
if (fptr==NULL)
{
printf("error in opening file \n" );
exit (1);
}
printf("position indicator in the beginning -- %ld \n", ftell(fptr));
while (fread(&emp,sizeof(emp),1,fptr)==1)
{
printf("position indicator-- %ld \n", ftell(fptr));
printf("%s \n", emp.name);
printf("%d \n", emp.empid);
printf("%f \n", emp.salary);
}
printf("%d \n", ftell(fptr));
fclose(fptr);
return 0;
}