Char String Array comparison / conversion

Hi there,

I’m trying to compare an Array element with String in my Arduino Uno project for the past 5-6 hours and I got an error message every time saying “cannot convert ‘String’ to ‘const char’”*

My code:

#include <SoftwareSerial.h>

SoftwareSerial RFID(2, 3);

int i;
String rfid_in = "";
char read_chr;
char* authTags[4][4];

void initauthTags() {

 authTags[0][0] = "22004C22FFB3"; 
 authTags[0][1] = "22004CD971C6"; 
 authTags[0][2] = "22004C317728"; 
 authTags[0][3] = "22004C0F4627";

 authTags[1][0] = "John"; 
 authTags[1][1] = "George"; 
 authTags[1][2] = "Peter"; 
 authTags[1][3] = "Josh";

}

void setup(){

 RFID.begin(9600);
 Serial.begin(9600);
 initauthTags();

}

void loop(){

 while(RFID.available() > 0){
  read_chr = RFID.read();
  rfid_in += read_chr;
 }

 for (i = 0; i < 4; ++i) {
  if (strcmp(authTags[0][i], rfid_in.c_str()) == 0) {
   Serial.println(authTags[1][i]); // Sends the Username to the Serial port
  }else{
   Serial.println("DENIDED");
  }
 }

}

I getting that error on IF statement line in the LOOP sequence, but I can’t figure out because I don’t know quite good this language.

Please help me to solve this issue for me! :frowning:

A String isn’t a char*, but you can access the one it implements internally:

strcmp( authTags[0], rfid_in.c_str() )[/b]

Ohhh, Thanks, I edited my code above!!! 8)

But I have now another issue, I got this output to my Serial monitor:

DENIDED
DENIDED
Peter
DENIDED

I wish to send only the name to Serial port not the entire loop sequence (Just to send Peter or DENIDED if the RFID Tag reading is wrong).

#define CHARS_EXPECTED=4;
void loop(){
  static int CharCount=0;

 while(RFID.available() > 0){
  read_chr = RFID.read();
  rfid_in += read_chr;
  CharCount++;
 }

 if(CharCount>=CHARS_EXPECTED) {
   for (i = 0; i < 4; ++i) { //what is 4? Why is it 4? Give it a #define name!
    if (strcmp(authTags[0][i], rfid_in.c_str()) == 0) {
     Serial.println(authTags[1][i]); // Sends the Username to the Serial port
    }else{
     Serial.println("DENIDED");
    }
    //now we've printed it, set the counter back to zero and wait for the next set of chars
    CharCount=0;
  }
 }

}

You’re still using capital-S Strings, but for such a simple example, it’s probably OK.

Why 4?! Its a Loop trough Tag array char* authTags[4][4];