Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!decwrl!labrea!rutgers!iuvax!pur-ee!uiucdcs!bradley!bucc2!nez From: nez@bucc2.UUCP Newsgroups: comp.sys.ibm.pc Subject: Re: Turbo C file size routine Message-ID: <32100013@bucc2> Date: Mon, 2-Nov-87 17:36:00 EST Article-I.D.: bucc2.32100013 Posted: Mon Nov 2 17:36:00 1987 Date-Received: Sat, 7-Nov-87 16:06:25 EST References: <2475@masscomp.UUCP> Lines: 48 Nf-ID: #R:masscomp.UUCP:2475:bucc2:32100013:000:1338 Nf-From: bucc2.UUCP!nez Nov 2 16:36:00 1987 /* Written by masscomp.UUCP!alang in comp.sys.ibm.pc */ > 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? > > Alan Groupe /* End of text from bucc2:comp.sys.ibm.pc */ How about trying something like: -------- | #define MAXSIZE 512 | | char temp_buf[MAXSIZE]; | | . | . | . | | i=0; | while( (i+=read(fp,temp_buf,MAXSIZE) )>0); --------- According to the Turbo C Reference manual, the function 'read' returns the number of bytes read and doesn't count ^Zs or ^Ms. Hope this helps... Rich Neswold =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= / bucc2!nez ...!ihnp4!bradley!- cyber!xx64194 \ buee730!nez =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= "It's a dirty, sadistic job - but somebody gets to do it."