File Concept
File Concept
• fseek(): The function fseek() is used to set the file pointer at the
specified position.
• The file pointer can be moved backwards or forward any number of
bytes.
• Syntax:
int fseek(FILE *fp, long offset, int start_point);
Program on fseek and ftell functions
#include <stdio.h>
#include<conio.h>
int main ()
{
FILE *fp;
int len;
clrscr();
fp = fopen("file.txt", "r");
fseek(fp, 0, 2); //file pointer fp moves to the end of file
len = ftell(fp);
fclose(fp);
printf("Total size of file.txt = %d bytes\n", len);
getch();
return(0);
}