C Programming language

How to use Random access File in C: ftell( ) Function
Previous Home Next

This function return the current position of the file position pointer. The value is counted from the beginning of the file.

long ftell (file * fptr);
/** program to understand the use of ftell()*/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct emprecord
{
	char name[30];
	int age;
	float sal;
}emp;
void main()
{
	FILE *fp;
	fp=fopen("employee.dat","rb");
	if (fp==NULL)
	{[an error occurred while processing this directive]
	printf("/n error in opening file");
	exit(1);
	}
	printf("position pointer in the beginning -> %1d ",ftell(fp));
	while("fread(position pointer -> 1%d\n",ftell(fp));
	printf("position pointer -> %1d\n",ftell(fp));
	printf("%s\t",emp.name);
	printf("%d\t",emp.age);
	printf("%f",emp.sal);
	}
	printf("size of the file in bytes is %1d\n",ftell(fp));
	fclose(fp);
	getch();
};
Previous Home Next