c guru (bit off topic)
John Speth
johns at oei.com
Tue Sep 21 18:11:19 CEST 1999
On Tuesday, September 21, 1999 8:51 AM, Andy Sloane
[SMTP:andy at guildsoftware.com] wrote:
> On Tue, Sep 21, 1999 at 12:01:11PM +0200, Martin Czech wrote:
> > Could one of the c gurus on this list please enlighten me:
> >
> > 1. I'm looking for a way to transfer files rapidly into dram.
> > There must be some kind of block-transfer stuff, but how
> > is this encoded in the librarys? fscanf is slow.
>
> You're looking for fread().
> fread(void *ptr, size_t num, size_t size, FILE *fp);
> if you want to read a 4k block, do something like char buf[4096];
> fread(buf, 4096, 1, fp);
A nice trick in using fread is to ask fread to get a preposterously huge
number of bytes and it will rad the entire file returning the actual number
of bytes contained in the file. Use a function like fstat to query the
size of the file first to take into account the possibility of read buffer
overruns. Be careful of that pesky binary vs. text issue (MS specific?)
with fopen.
John Speth
Object Engineering, Inc
mailto:johns at oei.com
More information about the Synth-diy
mailing list