It is necessary to check the correctness of the input at the input (example: 8 is correct, but an error). I know that for c ++ you can do this:

int n; if (cin.good()){ ... } 

And how to do the same, but not for cin, but for scanf. Tried scanf.good (), but does not work

    2 answers 2

    For scanf return value indicates the number of successfully read arguments. On it and rely.

    scanf is a function, do not try to add .good() mindlessly, where it does not make any sense. First of all - see the documentation.

      scanf returns the number of correctly read values. Those. if your scanf("%d",&n) returns not 1, then nothing is read ... If 0, then most likely because the format does not fit, if EOF is, then reading problems, not a single character is read .