c file size

Solutions on MaxInterview for c file size by the best coders in the world

showing results for - "c file size"
Ethan
01 Jan 2018
1FILE *fp = fopen("example.txt", "r");
2fseek(fp, 0L, SEEK_END);
3int size = ftell(fp);
Luis
06 Sep 2017
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;
Kris
05 Mar 2019
1If you use :
2
3/** 
4	Pay attention to return type! 
5	ftell returns long, which can only be used for files under 2GB. 
6**/
7fseek(f, 0, SEEK_END); // seek to end of file
8size = ftell(f); // get current file pointer
9fseek(f, 0, SEEK_SET); // seek back to beginning of file
10
11// If u want to get file of large size, use stat() instead
12struct stat buf;
13if(stat(filename, &buf) == -1){
14   return -1;
15}
16return (ssize_t)buf.st_size;
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 fseekusing 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 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 descriptorget 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 linuxsize of file fopenlinux read file size cc get file lengthc file lengthf size 28 29 example clinux find out size of filec get file size openfind 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 cget the size of a file in cthe size of files on cfind file length cfind size of a file in cc decrease file sizecheck the size of the file in linuxhow to get the size of a file in cc 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 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 cget sizeof file in chow to get length of file in csize of file cc measure file sizehow 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 cget size in bytes of file 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 charfile length in cgetting size of a file in cget file size of file linux 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 cget file size c posixfind the length of a file in cfstat get file sizec 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 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 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 cget file size using fseekhow to get size of file chow to get a size of the file linux cc mesure file sizec 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 chow to know swap file size in linuxget size of file chow to find the size of the file in cc program to get file sizehow to load a file in c sizec 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 cc file size