On 2012-06-23, Bill Cunningham <> 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
--
SDF Public Access UNIX System -
http://sdf.lonestar.org