Okay...I have been trying to give myself a crash course in serial communication was going really well until now), and I came across this little tidbit that makes no sense. I know C and C++, both of which completely ignore unnecessary spacing unless the situation deems it appropriate (EG when calling an API in C++ or inside the quotation marks on a printf() command in C), and I know that Arduino is based off of Wiring, which is based off of C, which makes me scratch my head and wonder where I went wrong.
My code:
/*
- eh, math...
*/int a=5;
int b=10;
int c=20;void setup()
{
Serial.begin(9600);
Serial.println("a = ");
Serial.print(a);
Serial.println("b = ");
Serial.print(b);
Serial.println("c = ");
Serial.print(c);
Serial.println("a+b = ");
Serial.print(a+b);
Serial.println("ac = ");
Serial.print(ac);
Serial.println("c/b = ");
Serial.print(c/b);
Serial.println("b-c = ");
Serial.print(b-c);
}
void loop()
{}
The serial output:
a =
5b =
10c =
20a+b =
15a*c =
100c/b =
2b-c =
-10
Now, for the confusing thing - this is the code copied and pasted from the site where I got it from (Arduino Tutorial - Lesson 4 - Serial communication and playing with data)
/*
- eh, math...
/
/- Math is fun!
*/int a = 5;
int b = 10;
int c = 20;void setup() // run once, when the sketch starts
{
Serial.begin(9600); // set up Serial library at 9600 bpsSerial.println("Here is some math: ");
Serial.print("a = ");
Serial.println(a);
Serial.print("b = ");
Serial.println(b);
Serial.print("c = ");
Serial.println(c);Serial.print("a + b = "); // add
Serial.println(a + b);Serial.print("a * c = "); // multiply
Serial.println(a * c);Serial.println("c / b = "); // divide
Serial.print(c / b);Serial.print("b - c = "); // subtract
Serial.printl(b - c);
}void loop() // we need this to be here even though its empty
{
}
Aaaand the output...
Here is some math:
a = 5
b = 10
c = 20
a + b = 15
a * c = 100
c / b =
2b - c =
-10
Now, I know that my version of the code isn't exactly "neat" as far as spacing and such goes, but I don't really see any point as it really doesn't matter all that much because I document well enough, and because like I said earlier, it's C. It usually doesn't matter all that much. I just can't understand why it's doing it this time.