sprintf causing weird serial issues?


hi all,

i'm working on project need formatting string, having weird bugs decided start isolating parts of project find out might causing issue.

part of project uses sprintf function format char array me. know arduino not support floating points numbers default sprintf, working integers , char[] right now.

the issue have found serial output start using sprintf goes crazy! it'll work fine before, call on function if not printing data serial output goes crazy!

my thought maybe serial library uses sprintf? i've posted code shows happens.

this code prints gibberish serial monitor

code: [select]
void setup() {

serial.begin(19200);

}

void loop() {

int tempreset = 5263;
char sincereset[] = "";
sprintf(sincereset, "since reset", tempreset);
serial.println("hello");
}


this code works fine!
code: [select]

void setup() {

serial.begin(19200);

}

void loop() {

int tempreset = 5263;
char sincereset[] = "";
//sprintf(sincereset, "since reset", tempreset);
serial.println("hello");
}



thanks in advance 

writing 0 length string not cleverest thing do.
(or should " getting sprintf write 0 length string "?  whatever)


Arduino Forum > Using Arduino > Programming Questions > sprintf causing weird serial issues?


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'