Subj : Re: newbie question [C language] To : comp.programming From : Rob Thorpe Date : Thu Jun 30 2005 09:17 am osmium wrote: > "Fred_NacH" writes: > > > I was wondering, how to retrieve the size/length of a file by only using > > the ansi functions... > > This one often causes a lot of controversy, some people say there is a > (usually unnamed) system on which it won't work or at least there *could > have been* a system on which it wouldn't work if such a system had been > built. > > Open the file in *binary* mode, seek to end of file, and use ftell() to see > where you are. If you like acrimony and pedantry, look around on Usenet for > these discussions which flare up from time to time. I expect the problem Randy points out is something like a bug - or at least lies in the neverland between bug and feature. fseek to SEEK_END isn't gauranteed to work on a binary file. I think this is because on some operating systems binary files are made from fixed size block of some number of bytes. They appear like files in other systems, but with nulls at the end padding out to the end of the block. It's worth pointing out that stat/fstat or a version of it are available on many platforms even though they aren't standard. .