Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!mit-eddie!ll-xn!ames!ucbcad!ucbvax!decvax!linus!philabs!trotter!bill From: bill@trotter.usma.edu (Bill Gunshannon) Newsgroups: comp.sys.ibm.pc Subject: Re: Turbo C file size routine Message-ID: <1005@trotter.usma.edu> Date: Fri, 6-Nov-87 08:47:02 EST Article-I.D.: trotter.1005 Posted: Fri Nov 6 08:47:02 1987 Date-Received: Tue, 10-Nov-87 04:07:06 EST References: <2475@masscomp.UUCP> <32100013@bucc2> Organization: US Military Academy, West Point, NY Lines: 48 Summary: Turbo C filelength In article <32100013@bucc2>, nez@bucc2.UUCP writes: > > /* 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. > > > > i=0; > > while (getc(fp) >= 0) i++; > > > > Is there a faster way to do this? > > > /* End of text from bucc2:comp.sys.ibm.pc */ > > How about trying something like: EXAMPLE USING read() DELETED FOR BREVITY > According to the Turbo C Reference manual, the function 'read' > returns the number of bytes read and doesn't count ^Zs or ^Ms. > Am I missing something here? Why not just use filelength()? And of course if you find that too boring there is another method: FILE *F0; long file_length, ftell(); int fseek(); fseek(F0,0L,SEEK_END); file_length = ftell(F0); I guess it just depends on how hard you want to make things. Another point in favor of the second method is it should be portable as fseek() and ftell() are standard routines and filelength() is not. Hope this helps. bill gunshannon UUCP: {philabs}\ US SNAIL: Martin Marietta Data Systems {phri } >!trotter.usma.edu!bill USMA, Bldg 600, Room 26 {sunybcs}/ West Point, NY 10996 RADIO: KB3YV PHONE: WORK (914)446-7747 AX.25: KB3YV @ K3RLI PHONE: HOME (914)565-5256