Strcmp or strcat , can we compare or concatenate with offset ? how please?

That won't work

The first method works because Buff2 is a pointer to the Buff2 array so adding 6 to it adds 6 to the address and it points to a starting point later in the array. However, Buff2[6] is a single character in the array so the comparison fails

However, this works

void setup()
{
    Serial.begin(115200);
    char Buff1[30] = "abcdefghijklmnopqrst";
    char Buff2[30] = "123456abcdefghijklmnopqrst";

    if (strcmp(Buff1, &Buff2[6]) == 0)
    {
        Serial.println("COMPARE TRUE");
    }
    else
    {
        Serial.println("COMPARE FALSE");
    }
}

void loop()
{
}

because the ampersand means "address of" rather than "value of"

1 Like