How can I obtain a file39s size in C

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

Possible Duplicate:
http://stackoverflow.com/questions/8236/how-do-you-determine-the-size-of-a-file-in-c http://stackoverflow.com/questions/8236/how-do-you-determine-the-size-of-a-file-in-c


How can I obtain a file s size in C? I opened with an application written in C. I would like to know the size, because I want to put the content of the loaded file into a string, which I alloc using malloc(). Just writing malloc(10000*sizeof(char)

Answers

You can use the fseek and ftell functions:

FILE* f = fopen("try.txt","rb");
fseek(f, 0, SEEK_END);
printf("size of the file is %ld", ftell(f));

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/10186643/how-can-i-obtain-a-files-size-in-c

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils