• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
August 15, 2022 |1.5K Views
C Program to Find Size of File
  Share   Like
Description
Discussion

In this video, we will write a C Program to find the size of a file. 

Methods:
 
1. Using fseek() and ftell() function: 
In this method, we will go to the end of the file using the inbuilt fseek() function. Then we will extract total bytes using inbuilt ftell(). function. A ftell() function returns a number of bytes moved from the start of the file. 

2. Using stat() function: 
The stat() function gets status information about a specified file and places it in the area of memory pointed to by the buf argument.
If the named file is a symbolic link, stat() resolves the symbolic link. It also returns information about the resulting file. 
Here we use size_t parameters, basically, it returns the block size of the file in bytes. This number is the number of bytes in a block of disk unit storage.

Example: 
Input file content: "Geeks for Geeks". 
Output: 15 bytes 

Input : file_name = "g.txt" 
Let "g.txt" contains "geeks" 
Output: 5 Bytes 

C Program to find size of a File
https://www.geeksforgeeks.org/c-program-find-size-file/

Read More