2012-07-11 142 views
0

我想爲液晶顯示器創建一個動態的printf大小,但它只輸出f =我做錯了什麼?printf動態長度/大小

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); 
+0

它看起來是正確的,並在這裏工作 – perreal 2012-07-11 11:34:19

回答

1

也許你需要這個:

 
char format[10]; 
int len1 = 5, len2 = 2; 
sprintf(format, "f=%%%d.%df", len1, len2); 
sprintf(buffer, format , (d = d + 0.01));