Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > confused about behaviour of scanf

Reply
Thread Tools

confused about behaviour of scanf

 
 
Chuck F.
Guest
Posts: n/a
 
      12-27-2005
those who know me have no need of my name wrote:
>
> in comp.lang.c i read:
>
> all your casts of ch to UCHAR are a waste of time -- mine to see
> it and yours to write it; heck even the compiler's, and the
> cpu's if code was emitted -- as the source of ch's value is
> getc, which provides exactly the value semantics you
> (redundantly) specify with the cast.


True enough. However you know that any bugs are not due to passing
a negative non-EOF value to isspace etc.
>
> in the readxwd and readxint functions you initially loop to skip
> blanks, yet earlier you defined a blank skipping function -- why
> aren't you using it? then again you specifically state that the
> user should skip blanks prior to calling the functions if that
> is their desire, so those loops seem contrary.


The code for skipping blanks was put in because it seemed more
efficient, and the code was trivial. The other notation is if the
user wants to also skip whitespace, which includes newlines,
vertical tabs, etc. a-la scanf.

>
>> digit = (unsigned) (ch - '0');

>
> this cast is also unnecessary, not the least because ch passed
> an isdigit test, but also because digit has type unsigned.


Also true. However you seem to have failed to quote the relative
portions, thus making it hard, or even impossible, for others to
understand what you are talking about.

This code has been lying about for 5 years or so here, waiting for
me to get a round tuit and polish it up. That's why it is missing
the ability to handle floats, longs, etc. and has not been bullet
proofed for max negative values. I posted it to satisfy someone
who worried about the line skipping when using scanf, as a means of
avoiding pre-assigned buffers.

Your criticisms seem not to affect the validity of the code.

--
Some informative links:
news:news.announce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html

 
Reply With Quote
 
 
 
 
those who know me have no need of my name
Guest
Posts: n/a
 
      12-27-2005
in comp.lang.c i read:
>those who know me have no need of my name wrote:
>> in comp.lang.c i read:


>>> digit = (unsigned) (ch - '0');

>> this cast is also unnecessary, not the least because ch passed
>> an isdigit test, but also because digit has type unsigned.

>
>Also true. However you seem to have failed to quote the relative
>portions, thus making it hard, or even impossible, for others to
>understand what you are talking about.


really? i described the test made against ch prior to this statement and
digit's type -- what is missing that would be needed for understanding?

further this statement exists exactly once in the large bulk of the
original post so is trivially easy to locate should a larger context be
desired. or are you saying that the references header is useless and i
should have copied in all the vastness just in case?

>This code has been lying about for 5 years or so here, waiting for me
>to get a round tuit and polish it up.


>Your criticisms seem not to affect the validity of the code.


i thought i'd (try to) help polish it. seems you don't like feedback.
sorry, i'll try to remember that, but hope that others still find value in
it.

--
a signature
 
Reply With Quote
 
 
 
 
Chuck F.
Guest
Posts: n/a
 
      12-28-2005
those who know me have no need of my name wrote:
> in comp.lang.c i read:
>

.... snip ...
>
>> Your criticisms seem not to affect the validity of the code.

>
> i thought i'd (try to) help polish it. seems you don't like
> feedback. sorry, i'll try to remember that, but hope that others
> still find value in it.


On the contrary, I welcome criticism. On the other hand what I
read into the general tone of your comments put me off, possibly
unreasonably.

--
Some informative links:
news:news.announce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html

 
Reply With Quote
 
Dave Thompson
Guest
Posts: n/a
 
      01-04-2006
On 21 Dec 2005 13:38:09 -0800, ""
<> wrote:

>
> Lalatendu Das wrote:

<snip classic FAQ 12.18'>
> what if we use
> scanf ("% c", &ch); //using a space between % and c
> Does this help to eliminate the new line charater in the buffer????


No. But if you use " %c" (space percent-c) it will skip all whitespace
(newline or other) and read the first non-whitespace char (if any).
- David.Thompson1 at worldnet.att.net
 
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
scanf(), ungetc() behaviour. Argento C Programming 62 10-06-2006 11:04 PM
difference between scanf("%i") and scanf("%d") ??? perhaps bug inVS2005? =?ISO-8859-1?Q?Martin_J=F8rgensen?= C Programming 18 05-02-2006 10:53 AM
scanf (yes/no) - doesn't work + deprecation errors scanf, fopen etc. =?ISO-8859-1?Q?Martin_J=F8rgensen?= C Programming 185 04-03-2006 02:49 PM
Scanf Behaviour sajjanharudit@gmail.com C Programming 7 12-30-2005 07:20 PM
Correct behaviour of scanf and sscanf Rob Thorpe C Programming 6 03-15-2005 04:25 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57