1

I have the following macro

I want to print a variable name then the value, so the macro will help having the variable name to show then its value

the result of my example show

var = 1.234 printed on the screen.

#include <stdio.h>

#define str(s) #s
#define PRINTER(X) printf("% 12s = % f\n", str(X), X);

int main()
{
   float var = 1.234f;
   PRINTER(var);// <===== warning here
   return EXIT_SUCCESS;
}

my question, if you try it, let me know if you get a warning within main, and what it mean?? for me I get flag ` ' used with type `s'

edit:

flag description

(space) If no sign is going to be written, a blank space is inserted before the value.

4

1 回答 1

2

Сhange

#define PRINTER(X) printf("% 12s = % f\n", str(X), X); 

to

#define PRINTER(X) printf("%12s = %f\n", str(X), X);`

Notice the space removed between % and specifier.

于 2013-08-08T13:47:52.697 回答