Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!amdahl!ames!sri-spam!rutgers!princeton!udel!rochester!PT.CS.CMU.EDU!andrew.cmu.edu!ks26+ From: ks26+@andrew.cmu.edu (Kenneth Sykes) Newsgroups: comp.sys.ibm.pc Subject: Re: Turbo C file size routine Message-ID: Date: Mon, 2-Nov-87 15:37:43 EST Article-I.D.: andrew.EVXCoLy00XoH8Kk0Bh Posted: Mon Nov 2 15:37:43 1987 Date-Received: Fri, 6-Nov-87 04:37:14 EST Organization: Carnegie Mellon University Lines: 37 In-Reply-To: <2475@masscomp.UUCP> >I'm looking for a way to determine the size of a text file from within Turbo >C. Determining the size of a binary file is trivial, using the stat call, >but if I open the file in text mode, stat returns the same value, which >is now incorrect (ie. CR/LF count as two characters in the count, although >are read as a single newline character. So far, I've been opening the file >in text mode and running the following loop, but this is slow: > > i=0; > while (getc(fp) >= 0) i++; > >Is there a faster way to do this? Assuming you want the file size as indicated by the DIR command, there are two approaches you can take: 1) If you don't mind opening the file, then use the following code: #include int fh; fh = _open(file, 0); = filesize(fh); _close(fh); 2) Otherwise, use the findfirst call: #include struct ffblk blk; if ( findfirst(file, , &blk) ) ; else = blk.ff_fsize; Since I am pulling the syntax off the top of my head, check the Reference manual to make sure I have the correct calling sequence, field names, etc. -- Ken Sykes