here you a go, I'm new to C so please show me a better way of this is wrong, thanks.
int filesize(FILE *handle)
{
fseek(handle,0,SEEK_END);
fsize=ftell(handle);
return fsize;
}
Printable View
here you a go, I'm new to C so please show me a better way of this is wrong, thanks.
int filesize(FILE *handle)
{
fseek(handle,0,SEEK_END);
fsize=ftell(handle);
return fsize;
}
@xoid:
an int possibly won't be big enough to hold the file size. Besides, ftell() returns a long int.
Also, fseeking to the end of a file isn't guaranteed to tell you the correct answer to the question. The file open mode can affect the answer too.
http://www.eskimo.com/~scs/C-faq/q19.12.html
maybe I'm wrong, but if you want to find an exact filesize you need Unix, LOL, I'm using windows, Visual C++ 6 compiler currently learning ANSI C, anything I could use that will guarantee the correct filesize?
thanks in advance
Use a binary open mode in your fopen() call. Then you can fseek()/ftell()
cool, is that the most efficient method under windows?
Yep.
You may also want to look up _stat() in MSDN or GetFileSize()Quote:
Originally posted by Xoid
cool, is that the most efficient method under windows?
aah! many thanks!