Johrdon Johrdon - 11 months ago 84
C++ Question

warning: more '%' conversions than data arguments [-Wformat] C++

I have this code:

fprintf( fitxer_sortida, "blob %d ->\t a=%7.0f\t p=%8.2f (%8.2f extern)\t pconvex=%8.2f\t ext=%.0f\t m=%7.2f\t c=%3.2f\t l=%8.2f\n",
i, area[i], perimetre[i], externPerimeter[i], perimetreConvex[i], exterior[i], compacitat[i], longitud[i] );

and I receive the error:

warning: more '%' conversions than data arguments [-Wformat]

What is the cause of this?

Ben Ben
Answer Source

You have 9 format specifiers and only 8 following printf arguments.

The warning explains itself. It is good that you have not ignored this, because the resulting behavior of this call is undefined.

To fix this either add the extra argument or remove one of the format specifiers (%).