Reputation: 3003
I'm trying to create a dynamic printf size for a lcd but it outputs only f= what do i do wrong?
sprintf(buffer, "f=%.2f", (d = d + 0.01)); <-- works but not dynamic
sprintf(buffer, "f=%.*f", 2 , (d = d + 0.01)); <-- Does not any give warning
lcd_puts(buffer);
_delay_ms(100);
Upvotes: 0
Views: 333
Reputation: 43311
Possibly you need this:
char format[10]; int len1 = 5, len2 = 2; sprintf(format, "f=%%%d.%df", len1, len2); sprintf(buffer, format , (d = d + 0.01));
Upvotes: 1