I'm reading a string of characters from serial but I'm only interested in one byte of data. I thought the most efficient way to do this was to use an array of 3 chars (char c[2] and look for my byte based on the bytes either side...
while (Serial.available() > 0) {
 c[0] = Serial.read();
 if (c[2] == 'P' && c[0] == 'V') {
  if (bitRead(c[1],0) == 0) {
   // do some stuff here
   }
  }
 c[2] = c[1];
 c[1] = c[0];
}
My code doesn't work. The last two lines are breaking it but I can't see what I'm doing wrong. I'm sure it's something basic.
I thought the most efficient way to do this was to use an array of 3 chars (char c[2] and look for my byte based on the bytes either side...
An array of 2 characters, one of which will be the NULL, you mean. The value in the brackets is the count, not the upper index. You need to allow room for the trailing NULL, too.
If your array "c" is a global or a static, the compiler will helpfully set all elements to zero, unless you tell it to set them to some other value.
Difficult to tell from snippets though (hint)