how would I check the return value to see that the scanf worked?
通过检查 scanf() 的返回值。
if( scanf("%d%d", &x, &y) != 2)
{
/* input error */
}
if (x > y)
{
printf("%d", x);
}
if(scanf("%lf%lf", &w, &z) != 2)
{
/* input error */
}
if ( w > z)
{
printf("%f", w);
}
来自scanf()文档:
These functions return the number of input items successfully matched
and assigned, which can be fewer than provided for, or even zero in
the event of an early matching failure.
The value EOF is returned if the end of input is reached before
either the first successful conversion or a matching failure occurs.
EOF is also returned if a read error occurs, in which case the error
indicator for the stream (see ferror(3)) is set, and errno is set
indicate the error.