c - Is there a way to use scanf with the "if" and "else" statements? -


i have create , call function main. have call scanf read 2 integers , print out bigger one. have scanf, time doubles instead of integers.

int main() {    int x, y;    scanf("%d%d", &x, &y);     if (x > y)    {       printf("%d", x);    }     scanf("%lf%lf", &w, &z);     if ( w > z)    {       printf("%f", w);    }     return 0; } 

i'm not sure if did right , how check return value see scanf worked? thanks.

in case, can check whether scanf() has worked succesfully or not follows,

if( scanf("%d%d", &x, &y) == 2) {    if (x > y)    {        printf("%d", x);    } } else {    printf("\nfailure"); } 

scanf() returns number of arguments successfuly read it.


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

php - Dynamic url re-writing using htaccess -

java - Multi-Label Document Classification -