Program to find size of a file

 

Consider the following code in which we are finding the size of a file by using fseek () and ftell () functions.

CODE:

# include <stdio. h>

# include <conio. h>

void main ()

{

FILE *fp;

char ch;

int s = 0;

fp = fopen (“FirstFile. txt”, “r”);

if (fp == NULL)

{

printf (“\n File cannot be opened”);

}

else

{

printf (“\n File opened”);

}

fseek (fp, 0, 3);

s = ftell (fp);

printf (“Size of file is %d\n”, s);

fclose (fp);

}