
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C Program to find size of a File
This is a C Program to find size of a File.
Algorithm
Begin function findfileSize() Open a file pointer fp in read only mode. If fp is equals to null then Print “File not found” and return -1. Else count the file size. Close the file. Put the file pointer at the beginning of the file Declare a integer variable result and initialize it with the output of the ftell() function. Close file pointer fp. Return result. End
Example
#include <stdio.h> int findfileSize(char f_n[]) { FILE* fp = fopen(f_n, "r"); // opening a file in read mode if (fp == NULL) // checking whether the file exists or not { printf("File Not Found!\n"); return -1; } fseek(fp, 0L, SEEK_END); int res = ftell(fp); //counting the size of the file fclose(fp); //closing the file return res; } int main() { char f_n[] = { "b.txt" }; //file name is “b.txt” whose size is to be determined int result = findfileSize(f_n); if (result != -1) printf("Size of the file is %ld bytes \n", result); //printing the file size return 0; }
Output
Size of the file is 2649 bytes
- Related Questions & Answers
- Python program to Find the size of a Tuple
- Program to find size of Doubly Linked List in C++
- C++ program to find minimum vertex cover size of a graph using binary search
- How to find the size of a list in C#?
- C++ program to find reduced size of the array after removal operations
- C# Program to rename a file
- C program to delete a file
- Program to find size of sublist where product of minimum of A and size of A is maximized in Python
- Write a C program to find total number of lines in an existing file
- C++ program to find perfect array of size n whose subarray is a good array
- C# program to get the extension of a file in C#
- C++ Program to Find Size of the Largest Independent Set(LIS) in a Given a Binary Tree
- Program to find latest group of size M using Python
- How to create a dummy file of any size with PowerShell?
- Write a program to Calculate Size of a tree - Recursion in C++
Advertisements