According to the return value of the scanf() function, judge whether the expected number of variable values are correctly read

 

#include<stdio.h>
int main()
{
    int a, b;
    if(scanf("%d %d", &a, &b)==2)
    {
        printf("a = %d, b = %d\n", a, b);
    }
    else
    {
        printf("Input error!\n");
    }
    return 0;
}

 

Guess you like

Origin blog.csdn.net/weixin_42048463/article/details/115001790