I would like to print an array of positions to the serial monitor using sprintf. But I am getting a string that prints the first element correctly, then a zero where the second element should be, and the second element where the third should be.
void setup() {
Serial.begin(9600);
long POS[3] = {123, 456, 789};
char DEBUG_STRING[50];
sprintf(DEBUG_STRING, "Position: %5d, %5d, %5d", POS[0], POS[1], POS[2]);
Serial.println(DEBUG_STRING);
}
Serial Monitor Result:
Position: 123, 0, 456