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

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -