mercredi 24 octobre 2018

C Scanf input testing for expected input format

I need to make a simple C program which will solve quadratic equation in expected format that needs to be like this:

a x^2 + b x + c = d x^2 + e x + f

I'm using scanf to read the input, and it works as expected. But I need to implement some input testing for my scanf reading which is like that right now:

scanf("%f x^2 + %f x + %f = %f x^2 + %f x + %f", &a, &b, &c, &d, &e, &f);

I need to printf("Wrong input\n"); for every input like f.e.

'abc', '1 x^2 + 1 x + 1 = 0', 'x^3...'

I tried the if (scanf() != 1), but it prints the 'Wrong output' every time. Any ideas about how can I accomplish that?

Aucun commentaire:

Enregistrer un commentaire