hi guys,
ok, i just realised something about scanf and its return values. when a user tries to assign (for example) three values to three variables, the return value of scanf is 3. nice.
THEN, if the user decides to input 4 values, return value of scanf is still three (since it reads only first three of them). where has the fourth value gone?
I'd like the user to be forced to input just three numbers by using:
but that does not work. if i give 4 values, programme gives no errors and carries on with calculations.Code:if ((scanf("%lf%lf%i", &num1, &num2, &num3)) == 3)
{
//some more of these calculations
}
else
{
printf("Wrong number of arguments\n");
return 1;
}
how would i restrict user to input only 3 values otherwise? is that a normal behavior for scanf?