I need to receive numbers until I press enter, I’ve tried to compare the returned value of the scanf with EOF but it keeps asking me to enter more numbers(infinite loop) :
int fail=0, late=0, avg=0, i=0, last=0, current, permission, difference;
while(scanf(" %d", ¤t) != EOF)
{
permission = (current < last);
difference = ((last - current) >= 30);
fail += difference*permission;
late += permission;
avg += (last - current)*(permission);
last = last*(permission) + current*(!permission);
}
Any suggestions.
thanx
Well, the scanf specification says that it will read and ignore any whitespace characters. Also, the specification says that EOF is returned only in case of an input failure before any data could be successfully read. You can read it by yourself here.
I would suggest using other reading functions as mentioned in other answers. Still, if you have to live and die with that scanf loop, perhaps you can add inside, at the bottom, the following code:
It should work if your input are only numbers and it’s just a way to make it work around.