C Programming
Computer Programming

C file handling program to Find the Size of File using File Handling Function



Write C file handling program to Find the Size of File using File Handling Function

\* C file handling program to Find the Size of File using File Handling Function *\

# include < stdio.h >
# include < stdlib.h >
int   main( )
{

FILE *fp ;
char ch ;
char filename[20] ;
int size = 0 ;

printf("\n Enter the filename to be opened : ") ;
scanf("%s", filename) ;
fp = fopen(filename, "r") ;
if (fp == NULL)
{
      printf(" Cannot open file ! \n") ;
      exit(0) ;
}

/* move file pointer at the end of file */
fseek(fp, 0, 2);

/* take a position of file pointer un size variable */
size = ftell(fp);
printf(" The size of given file is : %d\n", size);
fclose(fp) ;
return 0 ;

}

Output of Program :

Output of C file handling program to Find the Size of File using File Handling Function