librazone
asked on
File Size
Is there a way to get file size in c so that one can use it in an fread statement?thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Doesn't stat just open it anyway and fill up the values for easy access? At any rate, if you may not read the file that is probabily a better way to go about it
ASKER
Does this work for any file type?
>>Doesn't stat just open it anyway
from the following link , it doesnt seem so, even if it does , i think thats much faster.
anyways i meant he wont have to open by himself.
http://minnie.tuhs.org/UnixTree/V7/usr/src/libc/v6/stat.c.html
from the following link , it doesnt seem so, even if it does , i think thats much faster.
anyways i meant he wont have to open by himself.
http://minnie.tuhs.org/UnixTree/V7/usr/src/libc/v6/stat.c.html
>>Does this work for any file type?
do man stat
and look at the stat fields , from that u can know what kind of file is it,
and u can know much more than just sizeof file, , like number of blocks used, last accessed,modified,creatiio n time ..etc
do man stat
and look at the stat fields , from that u can know what kind of file is it,
and u can know much more than just sizeof file, , like number of blocks used, last accessed,modified,creatiio
in windows there is GetFileSize and open/read methods in case you dont have to be independant.
>>in case you dont have to be independant.
i hope he mean , platform independent .. and that too ur code and not u :)
i hope he mean , platform independent .. and that too ur code and not u :)
use stat() function an stat structure...
If using windows 95/NT
you can do this:
#include<io.h>
fp = fopen("test","rb");
handle = _fileno(fp);
len = _filelength(handle);
this is functions in visual c++
in borland there are corresponding functions I believe but without the underscores.
you can do this:
#include<io.h>
fp = fopen("test","rb");
handle = _fileno(fp);
len = _filelength(handle);
this is functions in visual c++
in borland there are corresponding functions I believe but without the underscores.
If you're going to read the entire file into one large array, you should ask whether mapping it is a better choice. See the mmap function.
Gary
Gary
ASKER
Thanks everyone.Actually I had accepted two answers this morning but for some reason it didnt go thru.