Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #22588

Re: fread/fwrite 2

From Ike Naar <ike@sverige.freeshell.org>
Newsgroups comp.lang.c
Subject Re: fread/fwrite 2
Date 2012-06-23 22:42 +0000
Organization A noiseless patient Spider
Message-ID <slrn3vfsjuchji.sf0.ike@sverige.freeshell.org> (permalink)
References <d426a544-98d9-42ea-9f36-37dfcf9b04f1@o4g2000yqk.googlegroups.com> <6bdd9df1-9a02-4b7b-b37b-57b1df00e197@t8g2000yqd.googlegroups.com>

Show all headers | View raw


On 2012-06-23, Bill Cunningham <me26us@yahoo.com> wrote:
> On Jun 23, 4:31?pm, Bill Cunningham <me2...@yahoo.com> wrote:
>> Ok after looking a Nick's old post again, I decided to try my own
>> copy. It seems to fill better with my style. Now it compiles can
>> copies fine. The thing is it hasn't been tested as to whether or not
>> it copied actual 2048 bytes at a time. I will submit it for review...
>>
>> #include <stdio.h>
>>
>> int main()

int main(void)

>> {
>> ? ? size_t nread = 0;
>> ? ? char buf[2048];
>> ? ? FILE *fpi, *fpo;
>> ? ? if ((fpi = fopen("t", "rb")) == NULL)
>> ? ? ? ? return -1;
>> ? ? if ((fpo = fopen("z", "wb")) == NULL)
>> ? ? ? ? return -2;
>> ? ? do {
>> ? ? ? ? nread = fread(buf, sizeof(buf), 1, fpi);

The second parameter of fread specifies the size of the
elemtents to be read, and the third parameter specifies the
(maximal) number of them. If you're going to read bytes instead
of 2048-byte blocks, it would be more natural to use

        nread = fread(buf, 1, sizeof buf, fpi);
  
>> ? ? ? ? if (ferror(fpi))
>> ? ? ? ? ? ? return -3;
>> ? ? ? ? fwrite(buf, sizeof(buf), nread, fpo);

and, to match the change in the fread arguments, here it would be

        fwrite(buf, 1, nread, fpo);

>> ? ? ? ? if (ferror(fpo))
>> ? ? ? ? ? ? return -4;
>> ? ? }
>> ? ? while (!feof(fpi));
>> ? ? fclose(fpi);
>> ? ? fclose(fpo);
>> ? ? return 0;
>>
>>
>>
>> }- Hide quoted text -
>>
>> - Show quoted text -
>
> Ok I guess there must be a short count somewhere in this code. Most of
> it has been copied I get no errors and I must admit I'm a little
> stumped. It's got to be in the fread fwrite system somehow.
>
> B


-- 
ike@sdf.lonestar.org
SDF Public Access UNIX System - http://sdf.lonestar.org

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

fread/fwrite 2 Bill Cunningham <me26us@yahoo.com> - 2012-06-23 13:31 -0700
  Re: fread/fwrite 2 Bill Cunningham <me26us@yahoo.com> - 2012-06-23 15:18 -0700
    Re: fread/fwrite 2 Ike Naar <ike@sverige.freeshell.org> - 2012-06-23 22:42 +0000
      Re: fread/fwrite 2 Bill Cunningham <me26us@yahoo.com> - 2012-06-24 12:51 -0700
        Re: fread/fwrite 2 Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-24 21:58 +0100
          Re: fread/fwrite 2 Bill Cunningham <me26us@yahoo.com> - 2012-06-24 14:36 -0700
            Re: fread/fwrite 2 Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-25 02:15 +0100
              Re: fread/fwrite 2 Bill Cunningham <me26us@yahoo.com> - 2012-06-25 13:15 -0700
                Re: fread/fwrite 2 Keith Thompson <kst-u@mib.org> - 2012-06-25 14:11 -0700
                Re: fread/fwrite 2 nick_keighley_nospam@hotmail.com - 2012-06-26 00:35 -0700
                Re: fread/fwrite 2 Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-26 13:30 +0100
      Re: fread/fwrite 2 Bill Cunningham <me26us@yahoo.com> - 2012-06-25 16:35 -0700
        Re: fread/fwrite 2 Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-26 03:18 +0100
          Re: fread/fwrite 2 Bill Cunningham <me26us@yahoo.com> - 2012-06-26 13:08 -0700
  Re: fread/fwrite 2 Bill Cunningham <me26us@yahoo.com> - 2012-06-23 15:32 -0700
    Re: fread/fwrite 2 John Gordon <gordon@panix.com> - 2012-06-24 14:01 +0000
      Re: fread/fwrite 2 Bill Cunningham <me26us@yahoo.com> - 2012-06-24 11:32 -0700
        Re: fread/fwrite 2 Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-24 20:06 +0100
          Re: fread/fwrite 2 Bill Cunningham <me26us@yahoo.com> - 2012-06-24 12:25 -0700

csiph-web