dave@cs.arizona.edu (Dave P. Schaumann) (01/14/91)
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.
mykes@zorch.SF-Bay.ORG (Mike Schwartz) (01/18/91)
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