Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > code

Reply
 
 
Ben Bacarisse
Guest
Posts: n/a
 
      09-04-2012
Barry Schwarz <(E-Mail Removed)> writes:

> On Tue, 04 Sep 2012 02:07:11 +0100, Ben Bacarisse
> <(E-Mail Removed)> wrote:
>
>>"Bill Cunningham" <(E-Mail Removed)> writes:
>>
>>> Ben Bacarisse wrote:
>>>
>>>> You should not be using scanf at all. It's the wrong tool for this
>>>> job. The simplest way to read binary data is with fread.
>>>
>>> This brings me to another question concerning feof(). I have this code I
>>> will post and Keith told me something I didn't quite get but it has stuck in
>>> my head and I'll address it. I knew this code would work so I have left out
>>> error checking for brevity. Am I using feof() right here or should I be
>>> doing something else?

>>
>>I wouldn't. In a similar style to what I suggested for scanf, I'd loop
>>based in success not the negation of failure. I'd test loop
>>
>> ...} while (nread > 0 && nwrite > 0);

>
> I suggest the second test should be nwrite == nread.


Yes, that's much better (and what I've written in real code more than
once -- I can't have been thinking). Thanks.

>>Anything other that this condition must be a problem of some sort. What
>>you've done is to test for one reason to stop: the end of the input, but
>>there are other possible problems: read errors and write errors
>>especially.


--
Ben.
 
Reply With Quote
 
 
 
 
Bill Cunningham
Guest
Posts: n/a
 
      09-04-2012
Kenneth Brody wrote:

> To be fair, it says "zero", not "0". However, I would hope you would
> know that the two are the same.
>
> It says, flat out:
>
> These functions return the number of input items assigned.
>
> First, you don't say what man page(s) you are showing, so I am going
> out on a limb and assuming that it's actually for fscanf(), as well
> as the related functions such as scanf() and sscanf(), hence the use
> of "these functions".


Yes. fscanf()

> Your call to fscanf is:
>
> *buf = fscanf(fp, "%i", buf);
>
> Hence, you are asking for (up to) 1 "item".
>
> Continuing the man page:
>
>>> This can be fewer than provided for, or even zero, in the event of
>>> a matching failure.

>
> Therefore, the only possible non-error returns are 0 and 1.
>
> Had you requested (up to) three items, then 0, 1, 2, and 3 would be
> the possible non-error returns. It would be impossible for the man
> page (or any other documentation, for that matter) to explicitly list
> every possible non-error return. The above two sentences describe
> the possible return values in enough detail for any Engligh-speaking
> programmer to extrapolate the exact list of possible values for the
> exact situation at hand.


OK to be humble I don't call myself a programmer at all. Not by a long
shot. I'm a wannabe. A dream. My approach to the whole fscanf thing I am
told was the wrong way to go.

Bill


 
Reply With Quote
 
 
 
 
Les Cargill
Guest
Posts: n/a
 
      09-04-2012
Bill Cunningham wrote:
> Kenneth Brody wrote:
>
>> To be fair, it says "zero", not "0". However, I would hope you would
>> know that the two are the same.
>>
>> It says, flat out:
>>
>> These functions return the number of input items assigned.
>>
>> First, you don't say what man page(s) you are showing, so I am going
>> out on a limb and assuming that it's actually for fscanf(), as well
>> as the related functions such as scanf() and sscanf(), hence the use
>> of "these functions".

>
> Yes. fscanf()
>
>> Your call to fscanf is:
>>
>> *buf = fscanf(fp, "%i", buf);
>>
>> Hence, you are asking for (up to) 1 "item".
>>
>> Continuing the man page:
>>
>>>> This can be fewer than provided for, or even zero, in the event of
>>>> a matching failure.

>>
>> Therefore, the only possible non-error returns are 0 and 1.
>>
>> Had you requested (up to) three items, then 0, 1, 2, and 3 would be
>> the possible non-error returns. It would be impossible for the man
>> page (or any other documentation, for that matter) to explicitly list
>> every possible non-error return. The above two sentences describe
>> the possible return values in enough detail for any Engligh-speaking
>> programmer to extrapolate the exact list of possible values for the
>> exact situation at hand.

>
> OK to be humble I don't call myself a programmer at all. Not by a long
> shot. I'm a wannabe. A dream. My approach to the whole fscanf thing I am
> told was the wrong way to go.
>
> Bill
>
>


It's a lot easier to get a copy of K&R and do the stuff in
there. If you get done early, do it twice

--
Les Cargill


 
Reply With Quote
 
Bill Cunningham
Guest
Posts: n/a
 
      09-05-2012
Les Cargill wrote:

> It's a lot easier to get a copy of K&R and do the stuff in
> there. If you get done early, do it twice


What I need as I'm learning is an example. And if I don't understand it
help. I don't know if kandr2 gives examples of everything I might overlook
and coming to clc can be questionable. If I ask for and example the answer
sometimes is "do your own work".

B


 
Reply With Quote
 
Bill Cunningham
Guest
Posts: n/a
 
      09-05-2012
There's also alot the kandr2 doesn't too. Like C99 for one. And
everything that printf can do.

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
what is the difference between code inside a <script> tag and code in the code-behind file? keithb ASP .Net 1 03-29-2006 01:00 AM
Fire Code behind code AND Javascript code associated to a Button Click Event =?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?= ASP .Net 4 02-11-2004 07:31 AM
Re: Code Behind vs. no code behind: error Ben Miller [msft] ASP .Net 1 06-28-2003 01:46 AM
Re: C# Equivalent of VB.Net Code -- One line of code, simple Ian ASP .Net 0 06-25-2003 01:14 PM
Re: C# Equivalent of VB.Net Code -- One line of code, simple Ron ASP .Net 1 06-24-2003 07:18 PM



Advertisments