C Program to find size of a File Last Updated : 28 Apr, 2018 Comments Improve Suggest changes Like Article Like Report Given a text file, find its size in bytes. Examples: Input : file_name = "a.txt" Let "a.txt" contains "geeks" Output : 6 Bytes There are 5 bytes for 5 characters then an extra byte for end of file. Input : file_name = "a.txt" Let "a.txt" contains "geeks for geeks" Output : 16 Bytes The idea is to use fseek() in C and ftell in C. Using fseek(), we move file pointer to end, then using ftell(), we find its position which is actually size in bytes. CPP // C program to find the size of file #include <stdio.h> long int findSize(char file_name[]) { // opening the file in read mode FILE* fp = fopen(file_name, "r"); // checking if the file exist or not if (fp == NULL) { printf("File Not Found!\n"); return -1; } fseek(fp, 0L, SEEK_END); // calculating the size of the file long int res = ftell(fp); // closing the file fclose(fp); return res; } // Driver code int main() { char file_name[] = { "a.txt" }; long int res = findSize(file_name); if (res != -1) printf("Size of the file is %ld bytes \n", res); return 0; } Comment More infoAdvertise with us Next Article C Program to find size of a File K Kanishk_Verma Follow Improve Article Tags : Misc C Programs C Language C++ cpp-file-handling C-File Handling +2 More Practice Tags : CPPMisc Similar Reads C Program to Find the Length of a String The length of a string is the number of characters in it without including the null character (â\0â). In this article, we will learn how to find the length of a string in C.The easiest way to find the string length is by using strlen() function from the C strings library. Let's take a look at an exa 2 min read C Program to Read Content of a File In C, reading a file is a step-by-step process in which we first have to prepare the file only after which we can start reading. It involves opening the file, reading its data, and closing the file.Opening the File: Opening the file loads the file into the memory and connect the file to the program 5 min read C Program to Find the Size of int, float, double and char Write a C program to find the size of the data types: int, float, double, and char in bytes and print it on the output screen.ExamplesInput: charOutput: Size of char: 1 byteInput: intOutput:Size of int: 4 bytesDifferent Methods to Find the Size of int, float, double and char in CWe can find the size 4 min read Lex program to find the Length of a String Problem: Write a Lex program to find the Length of a String Explanation: FLEX (Fast Lexical Analyzer Generator) is a computer program that generates lexical analyzers and was written by Mike Lesk and Eric Schmidt. Lex reads an input stream specifying the lexical analyzer and outputs source code impl 1 min read C Program to Print Contents of File C language allows users to process the files in its programs. Reading a file is a step-by-step process in which we first have to prepare the file only after which we can start reading. In this article, we will learn how to read and print the contents of a file using C program.The simplest method to 4 min read Like