sprintf .... why it does not work?


hello,

i'm trying this:

code: [select]


char buffer[50];
unsigned long tempo = 0;

.....

void loop(void) {
.......
tempo = millis();
sprintf( buffer , "%01d:%02d.%02d", tempo / 60000 , tempo / 1000 % 60, tempo % 1000 / 10 );
serial.println(buffer);
.....
}




i see on serial monitor:

quote
for example
2:00.23
2 minute , correct
:
00 zero, not correct
.
23 second, position not correct, must before dot
instead should see this:

quote
m:ss.ms

%01d = m 1 char minute zero
:
%02d = ss 2 char second zero
.
%02d = ms 2 char millisecond zero


why? can me?

%d expects int parameter, need %ld long.


Arduino Forum > Using Arduino > Programming Questions > sprintf .... why it does not work?


arduino

Comments

Popular posts from this blog

DHT11 Time out error using v0.4.1library

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!

Arduino Uno + KTY81/210 temperature sensor