Message-ID: <37B5BAFA.504E01BB@unb.ca> From: Endlisnis X-Mailer: Mozilla 4.61 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: length of file (baffling me) References: <7p3u7u$ncb$1 AT nnrp1 DOT deja DOT com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 27 Date: Sat, 14 Aug 1999 18:53:51 GMT NNTP-Posting-Host: 209.226.124.241 X-Trace: news21.bellglobal.com 934656831 209.226.124.241 (Sat, 14 Aug 1999 14:53:51 EDT) NNTP-Posting-Date: Sat, 14 Aug 1999 14:53:51 EDT Organization: Sympatico To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com jsc AT lds DOT co DOT uk wrote: > Hello all, this must be an easy question, but I can't seem to get it to work. > All I'm trying to do is work out the length of a file. I use > > FILE *fp; > fp = fopen(filename, "rb"); > printf( "File length: %i", filelength((int)fp) ); > > I get -1 returned, indicating an error, but I can't see why. > If anyone could help, I'd really appreciate it. If you would have read the documentation on the filelength function, you would have discovered that it takes an argument of a filedescriptor, and you can't just cast a FILE* to an int and hope it works. The docs clearly say to use the fileno macro. printf("File length: %i", filelength(fileno(fp))); -- (\/) Endlisnis (\/) s257m AT unb DOT ca Endlisnis AT HotMail DOT com ICQ: 32959047