Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > fread/fwrite

Reply
Thread Tools

fread/fwrite

 
 
Mark Bluemel
Guest
Posts: n/a
 
      06-21-2012
On Jun 21, 8:21*am, (E-Mail Removed) wrote:
> On Wednesday, June 20, 2012 4:17:28 PM UTC+1, Bill Cunningham wrote:
> > On Jun 20, 4:05*am, Mark Bluemel <(E-Mail Removed)> wrote:
> > > On Jun 19, 4:17*pm, (E-Mail Removed) wrote:
> > > > did you read what he wrote?

>
> > > Why would you expect Bill to do that? He's been around this group long
> > > enough for any regular reader to have some idea of his modus operandi..

>
> > > I can't decide whether he's a) simply incapable of learning or b) a
> > > subtle troll pretending to be a), though I'm beginning to lean towards
> > > b). Either way, I don't believe there is much point attempting to
> > > teach him.

>
> > * Things are not *taught* on clc. You do not learn anything.

>
> *you* might not. It's a technical news group. if you ask a technical question
> it's assumed you are interested in the answer! So you're just here to waste our time?


So it is b)...

>
> > *It is a C
> > social group. I can count on one hand what I've been *taught* on clc.

>
> that's because you're a cretin


No - if he's what I'm increasingly inclined to believe he is, then
he's rather clever, if somewhat perverse.

> > If you want to learn something on clc the response is generally...
> > "GIYF" or "I don't do homework." You do not learn C here. You talk
> > about it or your experience with C. I've learned more about writing C
> > on private mail groups in 1 month more than years on clc.

>
> I don't believe you've learnt anything


He's learnt how to yank your chain. I suggest kill-filing him and
updating your kill-file as he mutates his identity.
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      06-21-2012
On 06/22/12 07:05 AM, Kenneth Brody wrote:
> On 6/20/2012 7:56 PM, Ian Collins wrote:
>> On 06/21/12 11:47 AM, Bill Cunningham wrote:

> [...]
>>> I have read the man pages and googled them many times on fread and
>>> fwrite. I have tried to go by that and failed.

>>
>> The first hit I get for fread is
>>
>> http://www.cplusplus.com/reference/c.../cstdio/fread/

>
> Nit: I would probably avoid a domain called "cplusplus.com" if you were
> looking for answers regarding C, and not "that other language".


Except where it is discussing the shared standard library!

--
Ian Collins
 
Reply With Quote
 
 
 
 
James Kuyper
Guest
Posts: n/a
 
      06-21-2012
On 06/21/2012 03:17 PM, Ian Collins wrote:
> On 06/22/12 07:05 AM, Kenneth Brody wrote:
>> On 6/20/2012 7:56 PM, Ian Collins wrote:
>>> On 06/21/12 11:47 AM, Bill Cunningham wrote:

>> [...]
>>>> I have read the man pages and googled them many times on fread and
>>>> fwrite. I have tried to go by that and failed.
>>>
>>> The first hit I get for fread is
>>>
>>> http://www.cplusplus.com/reference/c.../cstdio/fread/

>>
>> Nit: I would probably avoid a domain called "cplusplus.com" if you were
>> looking for answers regarding C, and not "that other language".

>
> Except where it is discussing the shared standard library!


Even there.

Section 2 of annex C of the C++ standard has 3 1/2 pages listing the
ways in which the C++ version of the C standard library differs from the
C version. Unless you're familiar with precisely what those differences
are, you shouldn't assume that information about the C++ version will be
valid for the C version. Since only C/C++ experts are likely to have
that information, it's generally not a good idea for a newbie to go to
the wrong place for such information.

The only difference that matters for stdio.h is that NULL is a required
to be a C++ null pointer constant, rather than a C null pointer
constant. The simplest consequence is that NULL cannot expand to an
expression with type void*. The other consequence is that NULL can
expand to any one of several types of things that would not qualify as
integer constant expressions in C, such as:

1. An expression referring to a non-volatile const-qualified object of
integral or enumeration type, initialized with a integer constant
expression.
2. A value of type std::nullptr_t, such as nullptr.
3. A call to a constexpr function or constructor.

Offhand I can't come up with any way for this difference to affect a
strictly conforming C program, unless it makes use of the new C2011
_Generic feature, which is not (yet?) a part of C++.
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      06-21-2012
James Kuyper <(E-Mail Removed)> writes:
[...]
> Section 2 of annex C of the C++ standard has 3 1/2 pages listing the
> ways in which the C++ version of the C standard library differs from the
> C version. Unless you're familiar with precisely what those differences
> are, you shouldn't assume that information about the C++ version will be
> valid for the C version. Since only C/C++ experts are likely to have
> that information, it's generally not a good idea for a newbie to go to
> the wrong place for such information.
>
> The only difference that matters for stdio.h is that NULL is a required
> to be a C++ null pointer constant, rather than a C null pointer
> constant. The simplest consequence is that NULL cannot expand to an
> expression with type void*. The other consequence is that NULL can
> expand to any one of several types of things that would not qualify as
> integer constant expressions in C, such as:
>
> 1. An expression referring to a non-volatile const-qualified object of
> integral or enumeration type, initialized with a integer constant
> expression.
> 2. A value of type std::nullptr_t, such as nullptr.
> 3. A call to a constexpr function or constructor.

[...]

I wouldn't call that a difference in the library functions; rather
it's a difference in the languages, specifically in how they express
null pointer constants. The behavior of fread() and fwrite() when
given a null pointer as an argument is the same in both languages --
or, rather, it's undefined in both languages.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      06-21-2012
On 06/21/2012 06:08 PM, Keith Thompson wrote:
> James Kuyper <(E-Mail Removed)> writes:
> [...]
>> Section 2 of annex C of the C++ standard has 3 1/2 pages listing the
>> ways in which the C++ version of the C standard library differs from the
>> C version. Unless you're familiar with precisely what those differences
>> are, you shouldn't assume that information about the C++ version will be
>> valid for the C version. Since only C/C++ experts are likely to have
>> that information, it's generally not a good idea for a newbie to go to
>> the wrong place for such information.
>>
>> The only difference that matters for stdio.h is that NULL is a required
>> to be a C++ null pointer constant, rather than a C null pointer
>> constant. The simplest consequence is that NULL cannot expand to an
>> expression with type void*. The other consequence is that NULL can
>> expand to any one of several types of things that would not qualify as
>> integer constant expressions in C, such as:
>>
>> 1. An expression referring to a non-volatile const-qualified object of
>> integral or enumeration type, initialized with a integer constant
>> expression.
>> 2. A value of type std::nullptr_t, such as nullptr.
>> 3. A call to a constexpr function or constructor.

> [...]
>
> I wouldn't call that a difference in the library functions; rather
> it's a difference in the languages, specifically in how they express
> null pointer constants. The behavior of fread() and fwrite() when
> given a null pointer as an argument is the same in both languages --
> or, rather, it's undefined in both languages.


I was pointing out that it's a difference in the standard headers.
#include <stdio.h> is permitted in both languages, but the #definition
of NULL that results from that #inclusion can be a very weird animal,
from a C point of view, if you're using C++ to compile it. I believe
that the main point of defining nullptr was to allow

#define NULL nullptr

I wasn't addressing the specific issue of fread/fwrite, but the more
general issue of whether it's a good idea to rely upon a C++ source for
information about the C standard library. There are differences; there
aren't many, and they aren't major, but they do exist.

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      06-21-2012
James Kuyper <(E-Mail Removed)> writes:
[...]
> I wasn't addressing the specific issue of fread/fwrite, but the more
> general issue of whether it's a good idea to rely upon a C++ source for
> information about the C standard library. There are differences; there
> aren't many, and they aren't major, but they do exist.


Agreed.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
nick_keighley_nospam@hotmail.com
Guest
Posts: n/a
 
      06-22-2012
On Thursday, June 21, 2012 1:30:09 AM UTC+1, Ben Bacarisse wrote:
> Bill Cunningham <(E-Mail Removed)> writes:
>
> > On Jun 20, 7:40*pm, Ian Collins <(E-Mail Removed)> wrote:
> >
> >> As others have pointed out, you have been asking the same or similar
> >> questions here for many years.
> >>
> >> Your original question on this thread could easily have been answered
> >> with a quick search. *Quite often the search results for your questions
> >> include the thread from the previous time(s) you asked it!

> >
> > I have read the man pages and googled them many times on fread and
> > fwrite. I have tried to go by that and failed. That's why I asked for
> > an example. In other places people readily showed me one with no
> > problem and I see now what I might have been doing wrong. The man
> > pages I looked at gave no example. Only parameters and a somewhat
> > cryptic mention of ferror and feof.

>
> Here's an example (not my code):
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(void)
> {
> char buf [2048];
> FILE *fp_in;
> FILE *fp_out;
> size_t ch_read;
> if ((fp_in = fopen ("as.exe", "rb")) == NULL)
> {
> fprintf (stderr, "failed to open input file\n");
> exit (EXIT_FAILURE);
> }
> if ((fp_out = fopen ("a.exe", "wb")) == NULL)
> {
> fprintf (stderr, "failed to open output file\n");
> fclose (fp_in);
> exit (EXIT_FAILURE);
> }
> ch_read = sizeof(buf);
> while (ch_read == sizeof(buf))
> {
> ch_read = fread (buf, 1, sizeof(buf), fp_in);
> if ((ch_read != sizeof(buf) && ferror(fp_in))
> {
> fprintf (stderr, "read error\n");
> fclose (fp_in);
> fclose (fp_out);
> exit (EXIT_FAILURE);
> }
> if (fwrite (buf, 1, ch_read, fp_out) != ch_read)
> {
> fprintf (stderr, "write error\n");
> fclose (fp_in);
> fclose (fp_out);
> exit (EXIT_FAILURE);
> }
> }
> fclose (fp_in);
> fclose (fp_out);
> return 0;
> }
>
>
> It's Nick Keighley's example from 2008 -- simplified to remove a couple
> of possibly confusing C idioms.
>
> Source is Message-ID:
> <(E-Mail Removed)>


good grief.

 
Reply With Quote
 
nick_keighley_nospam@hotmail.com
Guest
Posts: n/a
 
      06-22-2012
On Thursday, June 21, 2012 3:17:22 PM UTC+1, Mark Bluemel wrote:
> On Jun 21, 8:21*am, (E-Mail Removed) wrote:
> > On Wednesday, June 20, 2012 4:17:28 PM UTC+1, Bill Cunningham wrote:
> > > On Jun 20, 4:05*am, Mark Bluemel <(E-Mail Removed)> wrote:
> > > > On Jun 19, 4:17*pm, (E-Mail Removed) wrote:


<snip>

> > > > I can't decide whether he's a) simply incapable of learning or b) a
> > > > subtle troll pretending to be a), though I'm beginning to lean towards
> > > > b). Either way, I don't believe there is much point attempting to
> > > > teach him.

> >
> > > * Things are not *taught* on clc. You do not learn anything.

> >
> > *you* might not. It's a technical news group. if you ask a technical
> > question it's assumed you are interested in the answer! So you're just
> > here to waste our time?

>
> So it is b)...
>
> > > It is a C social group. I can count on one hand what I've been
> > > *taught* on clc.

> >
> > that's because you're a cretin

>
> No - if he's what I'm increasingly inclined to believe he is, then
> he's rather clever, if somewhat perverse.
>
> > > If you want to learn something on clc the response is generally...
> > > "GIYF" or "I don't do homework." You do not learn C here. You talk
> > > about it or your experience with C. I've learned more about writing C
> > > on private mail groups in 1 month more than years on clc.

> >
> > I don't believe you've learnt anything

>
> He's learnt how to yank your chain. I suggest kill-filing him and
> updating your kill-file as he mutates his identity.


he certainly has. And someone has kindly posted an example =of mine=
from 4 years ago on the use of fread(). So it's not only Bill who is a
slow learner with a poor memory! Even if he isn't a troll (as many
people have suggested over the years) he has many of their attributes.

It was the suggestion that people don't even attempt to be helpful on
clc that finally blew the fuse.

 
Reply With Quote
 
Bill Cunningham
Guest
Posts: n/a
 
      06-22-2012
On Jun 21, 7:22*am, tom st denis <(E-Mail Removed)> wrote:
> On Jun 20, 7:47*pm, Bill Cunningham <(E-Mail Removed)> wrote:
>
> > On Jun 20, 7:40*pm, Ian Collins <(E-Mail Removed)> wrote:

>
> > > As others have pointed out, you have been asking the same or similar
> > > questions here for many years.

>
> > > Your original question on this thread could easily have been answered
> > > with a quick search. *Quite often the search results for your questions
> > > include the thread from the previous time(s) you asked it!

>
> > *I have read the man pages and googled them many times on fread and
> > fwrite. I have tried to go by that and failed. That's why I asked for
> > an example. In other places people readily showed me one with no
> > problem and I see now what I might have been doing wrong. The man
> > pages I looked at gave no example. Only parameters and a somewhat
> > cryptic mention of ferror and feof.

>
> I learned how to use fread/fwrite while using Turbo C++ 1.01 [or
> whatever the heck it was] which came free with a copy of "Type and
> learn C" that I got when I was 10 [20 some odd years ago...]
>
> Are you saying you're not as smart as a ten year old?
>
> Tom


Four years ago? On the Klonopin I was taking... Not as smart as a
five year old.

B
 
Reply With Quote
 
Bill Cunningham
Guest
Posts: n/a
 
      06-22-2012
On Jun 22, 3:22*am, (E-Mail Removed) wrote:

> he certainly has. And someone has kindly posted an example =of mine=
> from 4 years ago on the use of fread(). So it's not only Bill who is a
> slow learner with a poor memory! Even if he isn't a troll (as many
> people have suggested over the years) he has many of their attributes.
>
> It was the suggestion that people don't even attempt to be helpful on
> clc that finally blew the fuse.- Hide quoted text -


Now that I'm using google groups and figured out how to get Bill
Cunningham in the name section I am seeing where people can type in a
posters name and get old posts! And btw I have saved your example and
I'm studing it. I don't know about 4 years ago but the first thing I
wanted to change was insert a do while. I guess I didn't understand
that 4 years ago.

B
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments