compare chars?

is it possible to compare chars?

background info on what i'm trying to accomplish: i'm starting with the RFID tutorial, which stores the code of the 10-digit tag into a char array. if i know the value of a particular RFID tag, i want to be able to compare the known value to what is being read in (so that i know which RFID tag is being held up to the reader).

thanks, aya.

You probably want to use a function called memcmp().

It will compare a section of memory, like your 10 characters, and tell you if they are lesser, greater, or equal by returning <0, >0, or 0.

#include <string.h>

/* that include gets you: int memcmp(const void *b1, const void *b2, size_t len); */
/* it may already be included, it was in the sketch I just tested with. */

void loop()
{
  char a[10], b[10];

  // stuff happens

  if ( memcmp(a,b,10) == 0) {
    // more stuff happens
  }
}

i'm giving the memcmp a try, but running into a problem when filling my char array.

outside my void setup and void loop, i try to initialize a char like this: char tag1[10] = "F02D727AAA";

but i get this error: error: initializer-string for array of chars is too long huh? i count 10 characters there, how is that too long?

then i read in the help that for sequences of letter i should use single quotes and not double quotes. that give me a new error: error: invalid initializer

?? i am confused.

C strings have an implicit NUL character at the end. That is a character with the integer value of 0. You could make that array be 11 characters long and it would work.

thanks for the help. your note made me wonder about extra chars in the RFID code, and in fact they have a start byte and a stop byte i didn't know about (RTFM!). so increasing my char array from 10 to 12 worked. yay!