On Thursday, 11 January 2018 at 20:40:01 UTC, Dmitry Olshansky wrote:
   printf ("%.2f\n", d);

C’s printf by definition can’t be customized.


What did you expect?

To be honest: A compile time error. Modern C compilers can check such format strings. Example: GCC 6:

#include <stdio.h>

int main ()
   double d = 0;
   printf ("%p\n", d);
   return 0;

$ gcc -Wall mis.c
mis.c: In function 'main':
mis.c:6:14: warning: format '%p' expects argument of type 'void *', but argument 2 has type 'double' [-Wformat=]
    printf ("%p\n", d);

Reply via email to