Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!indetech!vsi1!zorch!mykes From: mykes@zorch.SF-Bay.ORG (Mike Schwartz) Newsgroups: comp.sys.amiga.programmer Subject: Re: Speeding up input Keywords: fgets vs read Message-ID: <1991Jan18.071607.16052@zorch.SF-Bay.ORG> Date: 18 Jan 91 07:16:07 GMT References: <659@caslon.cs.arizona.edu> Organization: SF-Bay Public-Access Unix Lines: 37 In article <659@caslon.cs.arizona.edu> dave@cs.arizona.edu (Dave P. Schaumann) writes: > >I have a program that reads in a text file and does processing on it. >Currently, I use fopen and fgets to access the file. I was wondering if it >would be faster to use open and read, and then roll my own fgets? > >I am using Manx V3.6a, if it matters. > >Dave Schaumann | We've all got a mission in life, though we get into ruts; >dave@cs.arizona.edu | some are the cogs on the wheels, others just plain nuts. > -Daffy Duck. Try the following: main() { UBYTE *buf; int fd, size; fd = open(filename, O_RDONLY); if (fd == -1) fail... size = lseek(fd, 0, 2); lseek(fd, 0, 0); buf = (UBYTE *)malloc(size); if (!buf) fail... read(fd, buf, size); close(fd); /* buf now points to your entire file */ ... } You can roll your own gets() function, or you can just parse through the buffer (which will be the fastest). I wouldn't do this under MS-DOS, but it works fine on the Amiga, as long as you have enough RAM to hold your file. Since it is text, you should have no problem. mykes