Here is source code of the C Program to find the size of file using file handling function. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
* C Program to Find the Size of File using File Handling Function
void main(int argc, char **argv)
int size = 0;
fp = fopen(argv, "r");
if (fp == NULL)
printf("\nFile unable to open ");
printf("\nFile opened ");
fseek(fp, 0, 2); /* file pointer at the end of file */
size = ftell(fp); /* take a position of file pointer un size variable */
printf("The size of given file is : %d\n", size);
$ vi file10.c $ cc file10.c $ a.out myvmlinux File opened The size of given file is : 3791744
Sanfoundry Global Education & Learning Series – 1000 C Programs.