Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: solution allocation of memory and composite numbers |
| Date | 2014-12-26 22:05 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <877fxegj8f.fsf@bsb.me.uk> (permalink) |
| References | (3 earlier) <874mskiz11.fsf@bsb.me.uk> <a11a0314-5e03-4100-93b9-e911f0ce8a73@googlegroups.com> <Q8Gmw.179333$td3.38698@fx34.am4> <87tx0kekzh.fsf@bsb.me.uk> <vfJmw.313270$td6.168835@fx30.am4> |
Richard Heathfield <invalid@see.sig.invalid> writes:
> Ben Bacarisse wrote:
>
>> Richard Heathfield <invalid@see.sig.invalid> writes:
>>
>>> Malcolm McLean wrote:
>>>
>>>> On Wednesday, December 24, 2014 8:16:59 PM UTC, Ben Bacarisse wrote:
>>>>> Malcolm McLean <malcolm.mclean5@btinternet.com> writes:
>>>>> <snip>
>>>>> > It's quite involved, unfortunately there's just no good way to
>>>>> > handle erroneous input, whatever you do it's difficult to program
>>>>> > robustly and give useful messages to the user.
>>>>>
>>>>> Yes, it is. So why not write
>>>>>
>>>>> if (scanf("%d", &number) == 1 && /* other checks... */) {
>>>>> /* use the input */
>>>>> }
>>>>>
>>>>> ? For this sort of program, beginners often get better code using
>>>>> scanf. There's plenty of time to learn abut parsing mini input
>>>>> languages later. The whole "you must use fgets & strtol" (both hard to
>>>>> use correctly) just puts a huge barrier up to getting started.
>>>>>
>>>> Richard Heathfield banned scanf().
<snip>
>>>
>>> And with good reason. Ben underestimates the difficulties that beginners
>>> have with scanf.
>>
>> No I don't. I have much experience of it.
>
> If you mean you have much experience of the function, I'm sorry to hear
> that. If you mean you have much experience of the difficulty that beginners
> have with it, then I'm... surprised that you advocate it.
The experience I have of the trouble beginners have with scanf tells me
that it's not as bad as you seem to suggest (what else could I have
meant?). It doesn't seem to me to "astoundingly difficult" to use
safely and correctly.
>> Might you be underestimating
>> the trouble beginners have with fgets and strtol (et al)?
>
> Oh, of course that's possible. But they aren't as hard to teach, or to
> learn, as scanf.
We will just have to agree to differ there. For reading a few numbers
in simple early programs I see no reason to ban scanf.
>>> It is an astoundingly difficult function to use safely and
>>> correctly.
>>
>> if (scanf("%d", &number) == 1)
Do you think this is "astoundingly difficult"?
>> is safe and correct, provided you get to choose what "correct" means,
>
> Not only do I get to choose what "correct" means, but I get to choose in
> which order I teach things, and input definitely comes before &.
Can you show me what you advocate to replace the line above so I can get
an idea of what you do teach before input. For example, do you gloss
over the array-to-pointer conversion in fgets? Do you avoid using the
second parameter of strtol? How much effort do you put in testing for
proper input?
I find a quick, "this lets scanf alter number -- you'll see what it
means in detail later" is all that's needed to explain the &.
>> and, as an instructor, you do! If you design the specification to suit
>> simple use of scanf, you can defer a whole lot of trouble until later.
>
> And if I design the specification to suit simple use of fgets and strtoul, I
> can defer a different whole lot of trouble until later. :-)
I'd like to see an example -- numerical input designed with fgets and
strtoul in mind, just so I can see what I might have been overlooking.
It doesn't seem simpler to me...
<snip>
--
Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
solution allocation of memory and composite numbers Dexterr <dejangru@gmail.com> - 2014-12-24 05:52 -0800
Re: solution allocation of memory and composite numbers Dexterr <dejangru@gmail.com> - 2014-12-24 05:55 -0800
Re: solution allocation of memory and composite numbers Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-12-24 06:41 -0800
Re: solution allocation of memory and composite numbers Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-12-24 20:16 +0000
Re: solution allocation of memory and composite numbers Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-12-24 12:39 -0800
Re: solution allocation of memory and composite numbers Richard Heathfield <invalid@see.sig.invalid> - 2014-12-24 21:22 +0000
Re: solution allocation of memory and composite numbers Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-12-24 22:33 +0000
Re: solution allocation of memory and composite numbers Richard Heathfield <invalid@see.sig.invalid> - 2014-12-25 00:54 +0000
Re: solution allocation of memory and composite numbers Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-12-24 18:38 -0800
Re: solution allocation of memory and composite numbers Vincenzo Mercuri <nomail@yahoo.it> - 2014-12-25 12:07 +0100
Re: solution allocation of memory and composite numbers Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-12-26 22:05 +0000
Re: solution allocation of memory and composite numbers BartC <bc@freeuk.com> - 2014-12-26 22:33 +0000
Re: solution allocation of memory and composite numbers Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-12-27 22:08 +0000
Re: solution allocation of memory and composite numbers BartC <bc@freeuk.com> - 2014-12-27 23:28 +0000
Re: solution allocation of memory and composite numbers BartC <bc@freeuk.com> - 2014-12-29 18:34 +0000
Re: solution allocation of memory and composite numbers raltbos@xs4all.nl (Richard Bos) - 2014-12-30 19:23 +0000
Re: solution allocation of memory and composite numbers Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-12-26 15:43 -0800
Re: solution allocation of memory and composite numbers Keith Thompson <kst-u@mib.org> - 2014-12-26 15:59 -0800
Re: solution allocation of memory and composite numbers Vincenzo Mercuri <nomail@yahoo.it> - 2014-12-27 14:45 +0100
Re: solution allocation of memory and composite numbers Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-12-27 21:55 +0000
Re: solution allocation of memory and composite numbers Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-12-27 14:07 -0800
Re: solution allocation of memory and composite numbers Vincenzo Mercuri <nomail@yahoo.it> - 2014-12-27 23:44 +0100
Re: solution allocation of memory and composite numbers Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-12-27 15:49 -0800
Re: solution allocation of memory and composite numbers Keith Thompson <kst-u@mib.org> - 2014-12-27 21:52 -0800
Re: solution allocation of memory and composite numbers Vincenzo Mercuri <nomail@yahoo.it> - 2014-12-28 15:54 +0100
Re: solution allocation of memory and composite numbers Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-12-28 00:03 +0000
Re: solution allocation of memory and composite numbers Keith Thompson <kst-u@mib.org> - 2014-12-26 17:13 -0800
Re: solution allocation of memory and composite numbers Geoff <geoff@invalid.invalid> - 2014-12-27 10:23 -0800
Re: solution allocation of memory and composite numbers Stephen Sprunk <stephen@sprunk.org> - 2014-12-27 13:03 -0600
Re: solution allocation of memory and composite numbers Keith Thompson <kst-u@mib.org> - 2014-12-27 12:24 -0800
Re: solution allocation of memory and composite numbers Keith Thompson <kst-u@mib.org> - 2014-12-27 12:23 -0800
Re: solution allocation of memory and composite numbers Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-12-27 13:31 -0800
Re: solution allocation of memory and composite numbers Öö Tiib <ootiib@hot.ee> - 2014-12-27 18:42 -0800
Re: solution allocation of memory and composite numbers Keith Thompson <kst-u@mib.org> - 2014-12-27 22:07 -0800
Re: solution allocation of memory and composite numbers raltbos@xs4all.nl (Richard Bos) - 2014-12-30 19:26 +0000
Re: solution allocation of memory and composite numbers Kaz Kylheku <kaz@kylheku.com> - 2014-12-30 20:01 +0000
Re: solution allocation of memory and composite numbers Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-12-30 12:18 -0800
Re: solution allocation of memory and composite numbers Kaz Kylheku <kaz@kylheku.com> - 2014-12-30 21:15 +0000
Re: solution allocation of memory and composite numbers Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-12-30 13:49 -0800
Re: solution allocation of memory and composite numbers Kaz Kylheku <kaz@kylheku.com> - 2014-12-30 22:03 +0000
Re: solution allocation of memory and composite numbers Kaz Kylheku <kaz@kylheku.com> - 2014-12-30 23:57 +0000
Re: solution allocation of memory and composite numbers BartC <bc@freeuk.com> - 2014-12-30 22:35 +0000
Re: solution allocation of memory and composite numbers Dr Nick <nospam-4@temporary-address.org.uk> - 2014-12-31 12:24 +0000
Re: solution allocation of memory and composite numbers Kaz Kylheku <kaz@kylheku.com> - 2014-12-31 17:08 +0000
Re: solution allocation of memory and composite numbers Dr Nick <nospam-4@temporary-address.org.uk> - 2014-12-31 17:37 +0000
Re: solution allocation of memory and composite numbers Kaz Kylheku <kaz@kylheku.com> - 2014-12-30 20:09 +0000
Re: solution allocation of memory and composite numbers Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-12-30 12:24 -0800
Re: solution allocation of memory and composite numbers Kaz Kylheku <kaz@kylheku.com> - 2014-12-30 21:28 +0000
Re: solution allocation of memory and composite numbers Malcolm McLean <malcolm.mclean5@btinternet.com> - 2014-12-30 13:53 -0800
Re: solution allocation of memory and composite numbers Kaz Kylheku <kaz@kylheku.com> - 2015-01-04 02:22 +0000
Re: solution allocation of memory and composite numbers Xavier Roche <xroche@free.fr.NOSPAM.invalid> - 2014-12-31 13:32 +0100
Re: solution allocation of memory and composite numbers BartC <bc@freeuk.com> - 2014-12-27 01:37 +0000
Re: solution allocation of memory and composite numbers raltbos@xs4all.nl (Richard Bos) - 2014-12-27 12:19 +0000
Re: solution allocation of memory and composite numbers gazelle@shell.xmission.com (Kenny McCormack) - 2014-12-27 14:39 +0000
Re: solution allocation of memory and composite numbers Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-12-24 22:29 +0000
Re: solution allocation of memory and composite numbers BartC <bc@freeuk.com> - 2014-12-24 15:05 +0000
Re: solution allocation of memory and composite numbers Richard Heathfield <invalid@see.sig.invalid> - 2014-12-24 16:55 +0000
iso646.h Noob <root@127.0.0.1> - 2014-12-25 18:26 +0100
Re: iso646.h Geoff <geoff@invalid.invalid> - 2014-12-25 18:31 -0800
Re: iso646.h Noob <root@127.0.0.1> - 2014-12-26 18:23 +0100
Re: iso646.h Keith Thompson <kst-u@mib.org> - 2014-12-25 21:31 -0800
Re: iso646.h fir <profesor.fir@gmail.com> - 2014-12-26 09:42 -0800
Re: solution allocation of memory and composite numbers Barry Schwarz <schwarzb@dqel.com> - 2014-12-24 09:06 -0800
Re: solution allocation of memory and composite numbers Richard Heathfield <invalid@see.sig.invalid> - 2014-12-24 16:59 +0000
Re: solution allocation of memory and composite numbers BartC <bc@freeuk.com> - 2014-12-24 17:26 +0000
Re: solution allocation of memory and composite numbers asetofsymbols@gmail.com - 2014-12-24 11:42 -0800
csiph-web