Read character to int without crashing

Pages: 12
Perhaps if I talk about what an argument list is, then you might understand this plain sentence.
scanf wrote:
On success, the function returns the number of items of the argument list successfully filled.

The argument list is the part that comes after the format specifier.
In scanf("%d %d %d", &x, &y, &z) the argument list is &x, &y, &z
scanf will attempt to fill these arguments by reading from stdin, but if it fails then the returned number will be less than 3. If scanf did return a 3, then it succesfully filled 3 things from the arguments list.

The following sentence explains why a number less than the number of arguments in the argument list might be returned.
scanf wrote:
This count can match the expected number of items or be less (even zero) due to a matching failure, a reading error, or the reach of the end-of-file.
That makes sense now, thanks.
Topic archived. No new replies allowed.
Pages: 12