Very simple code with a problem

Hi guys I’m wondering why in this little program, the serial output is NOT being indented (\t)?
If i change the data types of x,y and z from int to float, it works. Later testing showed me that it works with int too ONLY IF the number is greater than 2 digits, and by that I mean >=10 OR <0 (minus sign counts).

Its basically a problem I’m having with another code I’ve just made it really simple here so everyone can run it quickly and hopefully I can get more answers faster ^.^…

int x;
int y;
int z;

void setup() {
  Serial.begin(9600);
}

void loop() {
  x = 0;
  y = 0;
  z = 0;
  Serial.print("X is: ");
  Serial.print(x);

  Serial.print("\tY is: ");
  Serial.print(y);
  
  Serial.print("\tZ is: ");
  Serial.println(z);
  delay(1000);  
}

Thanks!

scopesys:
Hi guys I’m wondering why in this little program, the serial output is NOT being indented (\t)?
If i change the data types of x,y and z from int to float, it works. Later testing showed me that it works with int too ONLY IF the number is greater than 2 digits, and by that I mean >=10 OR <0 (minus sign counts).

Its basically a problem I’m having with another code I’ve just made it really simple here so everyone can run it quickly and hopefully I can get more answers faster ^.^…

int x;

int y;
int z;

void setup() {
  Serial.begin(9600);
}

void loop() {
  x = 0;
  y = 0;
  z = 0;
  Serial.print("X is: ");
  Serial.print(x);

Serial.print("\tY is: “);
  Serial.print(y);
 
  Serial.print(”\tZ is: ");
  Serial.println(z);
  delay(1000); 
}




Thanks!

the reason is because \t is calling a “tab” function basiclly. But the start of the tab spacing isnt set by the last char you have entered into your code but from a base point of 0. so whats happening is most of your tab is being eatten up by x = 0 and v = 0 ect.
by adding a simple space before the tab i have moved the tabs starting space to a new reset location if that makes sense.

int x;
int y;
int z;

void setup() {
Serial.begin(9600);
}

void loop() {
x = 0;
y = 0;
z = 0;
Serial.print("X is: ");
Serial.print(x);

Serial.print(" \tY is: ");
Serial.print(y);

Serial.print(" \tZ is: ");
Serial.println(z);
delay(1000);
}

The \t character inserts the tab (ascii char 9) into the string, and the ascii tab width is a field 8 characters wide. The tab will jump from where the text stops in the 8 character block to the next field. If you have used up 5 characters it will jump 3. In your case, with your text and one digit number, you use up 7 and it jumps one. When you use a two digit number which brings the total to 8 characters, tab jumps across the full field to the next starting point.

cattledog: The \t character inserts the tab (ascii char 9) into the string, and the ascii tab width is a field 8 characters wide. The tab will jump from where the text stops in the 8 character block to the next field. If you have used up 5 characters it will jump 3. In your case, with your text and one digit number, you use up 7 and it jumps one. When you use a two digit number which brings the total to 8 characters, tab jumps across the full field to the next starting point.

Thank you both, what Remy suggested worked but I didn't quite understand why from his post however your explanation cleared things up for me ^.^... I got a question though, why 8? Does it have something to do with 8 chars (each 1 bit?) representing 1 byte and what tab does is skip to the next byte? Sorry I'm very new to programming xD

Does it have something to do with 8 chars (each 1 bit?) representing 1 byte

No. It is an arbitrary number chosen by the writers of the Serial monitor as a compromise between being useful and wasting space.