String comparison not working

The following code is taken from a keyboard emulator program that I’m working on:

/*
 * Test
 */

#include <avr/pgmspace.h>
#include <string.h>

typedef struct PROGMEM
{
      char myCode[3];
      byte ctlScanCode;
      int type;
} ctlKeyTable_t;

ctlKeyTable_t ctlKeyTable[] PROGMEM = {
      {"BK", 0x66, 1},  // BKSP
      {"CP", 0x58, 2},  // CAPS
      {"EN", 0x5A, 1},  // ENTER
      {"ES", 0x76, 1},  // ESC
      {"F1", 0x05, 3},  // F1
      {"F2", 0x06, 1},  // F2
      {"F3", 0x04, 1},  // F3
      {"F4", 0x0C, 1},  // F4
      {"F5", 0x03, 2},  // F5
      {"F6", 0x0B, 1},  // F6
      {"F7", 0x83, 1},  // F7
      {"F8", 0x0A, 1},  // F8
      {"F9", 0x01, 1},  // F9
      {"FA", 0x09, 1},  // F10
      {  "", 0x00, 0}   // end of array
};

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

void loop() {
delay(5000);
      {
            {
            char buffer1[3];
            int i = 0;
            while ( i != 14) {
                        strcpy_P(buffer1, ctlKeyTable[i].myCode);
                        byte buffer2 = pgm_read_word(&(ctlKeyTable[i].ctlScanCode)); 
                        int  buffer3 = pgm_read_word(&(ctlKeyTable[i].type)); 
                        Serial.println(buffer1);
                        Serial.println(buffer2,HEX);
                        Serial.println(buffer3);
                        Serial.println();
                        if ( buffer1 == "F3" ) break;       // <<< NEVER WORKS!
                        i++;
                  }
            }
      Serial.println("---------------------");
      }
}

It starts by creating a structure definition and an array in program memory. The loop that follows simply displays the array contents, line by line, and this work fine. The problem is when I try to break the counter loop with the IF statement. Even though buffer1 is displayed as “F3” at the appropriate point in the loop, the break function never happens when it encounters “F3”.

Why does the Serial.print statement work when it gets to the F3 entry, but the break statement doesn’t?

Sorry if this is a naive question, I’m a complete newbie. I’ve played around with pointers and dereferencing, but I still don’t get it.

Any help will be very gratefully received.

Regards to all,
Mark.
Ottawa, Ontario, Canada.

buffer1 == "F3"

Sorry, no can-do; "buffer1" is pointer to a byte (char) array, "F3" is a constant string. You need to compare character by character. No worries though, there are only two! Or use "strcmp"

Thanks for the response AWOL.

So would it be something like?:

if (buffer1[0] == 'F' && buffer1[1] == '3') break;

That's a bit of a pain since this will become a function to which I'll be passing a variable 2-character string, which I would also have to break apart.

Or, if I use strcmp would it be?:

int j = strcmp(buffer1, "F3"); if (j == 0) break;

That seems simple enough.

Can I say?:

if (strcmp(buffer1, "F3") ==0) break;

where "F3" will become a variable that I pass to the function?

Mark.

if (strcmp(buffer1, “F3”) ==0) break;

Yup, perfect.