how to check the size of a file c

Solutions on MaxInterview for how to check the size of a file c by the best coders in the world

showing results for - "how to check the size of a file c"
Charlotte
10 Jul 2020
1FILE *fp = fopen("example.txt", "r");
2fseek(fp, 0L, SEEK_END);
3int size = ftell(fp);
Kevin
06 Jan 2021
1If you have the file stream (FILE * f):
2
3fseek(f, 0, SEEK_END); // seek to end of file
4size = ftell(f); // get current file pointer
5fseek(f, 0, SEEK_SET); // seek back to beginning of file
6// proceed with allocating memory and reading the file
7
8Or,
9
10#include <sys/types.h>
11#include <sys/stat.h>
12#include <unistd.h>
13fd = fileno(f); 
14struct stat buf;
15fstat(fd, &buf);
16int size = buf.st_size;
17
18Or, use stat, if you know the filename:
19
20#include <sys/stat.h>
21struct stat st;
22stat(filename, &st);
23size = st.st_size;
Carys
06 Jul 2019
1// C program to find the size of file 
2#include <stdio.h> 
3
4long int findSize(char file_name[]) 
5{ 
6	// opening the file in read mode 
7	FILE* fp = fopen(file_name, "r"); 
8
9	// checking if the file exist or not 
10	if (fp == NULL) { 
11		printf("File Not Found!\n"); 
12		return -1; 
13	} 
14
15	fseek(fp, 0L, SEEK_END); 
16
17	// calculating the size of the file 
18	long int res = ftell(fp); 
19
20	// closing the file 
21	fclose(fp); 
22
23	return res; 
24} 
25
26// Driver code 
27int main() 
28{ 
29	char file_name[] = { "a.txt" }; 
30	long int res = findSize(file_name); 
31	if (res != -1) 
32		printf("Size of the file is %ld bytes \n", res); 
33	return 0; 
34} 
35
queries leading to this page
c programming check file sizec how to get size of filefile size chow can i see the size of a file in cfind big file size in cbinary file size c filec small file sizesize of file from fseeksizeof file in cusing ftell as array size chow to create a file in c with a sizeget length of file chow to get size of file in cfind file size chow to get size of a file in cprint file size in cc get txt file sizeget file size unix chow to find the size of a file c 2b 2b linuxc get length of filedimension char to size of filelinux get file size fseekhow to get file size chow to get file name and its type using metadata in linux using cc length of a filehow to know a size of a file in chow to calculate size of file in cc get file size by descriptorrealloc in c and size of a fileget file stream filename and size chow to get the file size in chow to check the size of a file in linux ccheck size of file linuxhow to find the length of a file in csize of file fopenlinux read file size cc get file lengthc file lengthf size 28 29 example csizeof file type clinux find out size of filec get file size openget fiel size stdiohow sizeof works in cfind total size of a file in cget size of file in csize of file in chow to make c know the size of a filehow to know size of file in linuxlenght of file in cget file size cc get file sizeget file length cget file size c sizeofsize of a file csize write file in cget the size of a file in cthe size of files on cfind file length cc length of filefind size of a file in cc decrease file sizeget file size of file in windows ccheck the size of the file in linuxhow to get the size of a file in cwrite c program to calculate the length of a filec program how to find file size of a filecheck file size chow to know size of file in cfscanf c size of filec file sizefile size in c statget file size using statget allocated size of file cdetermine length of file in chow to check the size of a file chow to check size of file in linuxhow to check the size of a binary file chow to now a size of a file in cdisplay size of text file c programmingget sizeof file in chow to get length of file in csize of file cmodify size of file in cc measure file sizehow to display the size of a file in chow to get a size of a file in cc using stat to get file sizec read whole file of any sizehow to check size of file 2a in cwhat is the size of data type file in cget size in bytes of file clength of a file in chow to find size of a file in cknow bytes of a file chow to determine file size in cc get the size of a file in charget size of a file cc open file sizehow to find the size of write file in read function in cfile length in cgetting size of a file in cget file size of file linux cfile get size cc print file sizemake a file smaller in size in chow to know the size of a file in linuxsize of a file in cc check size of filec print current file sizefind the size of the file in chow to specify size of created file in cc code size of filec how to get the size of a fliecalculate file size in cget file size in cc get the total bytes from filesizeof c filec read file sizeget size of file c opengettinf a file size in chow to check the size of a file in linuxget the size of a file csizeof file cget file size c posixfind the length of a file in cfstat get file sizewhat is the size of file in cc find length of a filec show amount of bytes in a filec determine file sizesize of the file in chow to get file size in cfile length chow to find the size of write file using fd in cc get file size in bytesfind size of binary file in chow to find file size in cfind size of a text file in cfind size of text file cfind big files size in cc get size of fileget file size opening a filehow to find the size of a file in cknowbytes of a file chwo to get the size of a file in chow free in c know the sizeget file size using fseekhow to get size of file chow to get file content size in chow to find the size of file in read function in chow to get a size of the file linux cc mesure file sizefread 2c size of file in cc size of filefilesize em chwo big should your main file be in cc size file 2ac sizeof filecalculate file length cfile size in chow to get the size of any file in clinux check size of a filec get file size lseek and readc how to get size of file in byteslinux file size c programhow to get the size of a file cget size of a file in cget length of file in chow to know swap file size in linuxlength of file cget size of file chow to find the size of the file in chow to see in a file wich is bigger in cc program to get file sizehow to load a file in c sizeidentify file size in cc get file size unixswitch for ls to view innode number linuxhow to get actual size of a file in cget file lengthfastest way to get file size in ccan you use sizeof command on files using chow to check the size of a file c