This C Program finds the size of file using file handling function.
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
*/
#include <stdio.h>
void main(int argc, char **argv)
{
FILE *fp;
char ch;
int size = 0;
fp = fopen(argv[1], "r");
if (fp == NULL)
printf("\nFile unable to open ");
else
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);
fclose(fp);
}
$ 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.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement
Here’s the list of Best Books in C Programming, Data-Structures and Algorithms
If you wish to look at programming examples on all topics, go to C Programming Examples.
Next Steps:
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Apply for Computer Science Internship
- Buy Computer Science Books
- Practice BCA MCQs
- Apply for C Internship
- Watch Advanced C Programming Videos