0 breaks array

Hi everybody,

I was doing a test with 2 dimensional arrays and I've got a problem which I'm sure has come up here before, but I don't know in what terms to look for the answer:

Basically I'm trying to assign 11 bytes to each element of the array 'positie', and to to print those strings one after another to the serial port. I've noticed that by using Serial.print(positie[n]), it will print out all the bytes unless there's a 0 found (as in positie[0] the second element).

How would I work around this? I need it to print all the bytes out, even if there's a 0 present. Am I obligated to write a for-loop for each printout?

Thanks a lot! Jens

char positie[2][15] = {
  {1,0,3,4,5,6,7,8,9,11,0x61},
  {14,15,16,17,18,19,20,21,22,23,0x62}
};
  
void setup(){
  Serial.begin(57600);
}

void loop(){
  Serial.print(positie[0]);
  delay(2000);
  Serial.print(positie[1]);
  delay(2000);
}

I would think it is being treated as the null terminator for the string. Your array contains 0x01, 0x00, 0x03..., not the characters '1', '0', '3'..., if that's what you are expecting to see printed.

Your array contains 0x01, 0x00, 0x03..., not the characters '1', '0', '3

I know, most of the bytes I will use in my project are upfront in the ASCII table (like for example 0x0F), so I know I'm trying to print out mostly non-printable characters. However, I wouldn't like to see not all the bytes passed if for one reason or another there would be a real 0x00 somewhere in te middle.

Then you'll probably have to Serial.write() them, one at a time.

You might have to address it as a pointer. http://www.cplusplus.com/doc/tutorial/pointers/

StackOverflow has alos addressed this issue. http://stackoverflow.com/questions/5767249/how-do-i-run-through-a-2d-array-that-contains-3-values-and-run-a-check-for-the-v

You need to treat them as arrays and not strings because as already pointed out the zero is a string terminator.

Something like this:-

char positie[2][15] = {
  {1,0,3,4,5,6,7,8,9,11,0x61},
  {14,15,16,17,18,19,20,21,22,23,0x62}
};
  
void setup(){
  Serial.begin(57600);
}

void loop(){
  for(int i=0; i<11; i++){
  Serial.print(int(positie[0][i]));
  delay(600);
  }
  Serial.println(" ");
  for(int i=0; i<11; i++){
  Serial.print(int(positie[1][i]));
  delay(600);
  }
  Serial.println(" ");
  Serial.println(" ");
}

Thanks a lot guys,

I think I'll figure it out from here!