Re: a scanf() question



Richard Bos said:

"Mik0b0" <newssw@xxxxxxxxx> wrote:

I have trouble finding a solution to this problem: how to pick up 10
numbers
corresponding to certain criteria (-399>=number<=400) from the input?
The number of input numbers is not limited. Thanks!

You don't. You read numbers from the input (or, if you're wise, you read
strings, and then attempt to convert those to numbers - much less prone
to breakage when someone enters "three" rather than "3"); and _then_ you
check whether the number you read is within the desired limits. There is
no single function in C that can read a number only if it's larger or
smaller than a certain limit.

By "no single function" Richard means "no single standard library function",
and by "a certain limit" he means "a certain user-imposed limit".

The second nit refers to the fact that scanf can only read a number that is
within the range of values for the given type, and the first refers to the
fact that any competent C programmer can write a C function to do what is
required and so it is entirely possible - even likely - that someone
already has.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
.