Re: a scanf() question
- From: Simon Biber <news@xxxxxxxxx>
- Date: Tue, 28 Nov 2006 23:31:51 +1100
Mik0b0 wrote:
Good day to everyone,
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!
#include <stdio.h>
int main(void)
{
int i,n;
for(n = 0;
n < 10 && scanf("%d", &i) == 1;
n += -399 <= i && i <= 400);
return 0;
}
Here's an example run:
C:\docs\prog\c>a
100
200
300
400
500
600
700
800
100
200
300
400
500
600
700
800
100
200
It ignored the 500, 600, 700 and 800 in the input, and continued taking input until it had read 10 numbers in the correct range. Those were 100, 200, 300, 400, 100, 200, 300, 400, 100, 200.
--
Simon.
.
- Follow-Ups:
- Re: a scanf() question
- From: Mik0b0
- Re: a scanf() question
- References:
- a scanf() question
- From: Mik0b0
- a scanf() question
- Prev by Date: Re: Reading a string of unknown size
- Next by Date: Re: Reading a string of unknown size
- Previous by thread: Re: a scanf() question
- Next by thread: Re: a scanf() question
- Index(es):
Relevant Pages
|