help with arduino and rfid reader

i’m trying to program my arduino so that when the connected rfid reader reads a card, the card’s code is compared to an authorized code stored in eeprom. If the codes match, the arduino sends “Valid!” to the serial monitor, and “Invalid!” if they don’t. The problem is…all cards trigger the “Invalid!” message, even the card whose code is stored in the eeprom (i.e authorized). Please help

#include <EEPROM.h>
#include “EEPROMAnything.h”
int val = 0;
char code[10];
char validCode [10];
int bytesread = 0;
#define buttonPin 10

void setup(){
Serial.begin (2400);
pinMode(2,OUTPUT);
pinMode (10, INPUT);
digitalWrite(2, LOW);
}

void loop() {

if(Serial.available() > 0) { // if data available from reader
if((val = Serial.read()) == 10) { // check for header
bytesread = 0;
while(bytesread<10) { // read 10 digit code
if( Serial.available() > 0) {
val = Serial.read();
if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
break; // stop reading
}
code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
}
}
if(bytesread == 10) { // if 10 digit read is complete
EEPROM_readAnything (0, validCode);
if (code == validCode){
Serial.println (“Valid!”);
}
else{
Serial.println (“Invalid!”);
}
}
bytesread = 0;
digitalWrite(2, HIGH); // deactivate the RFID reader for a moment so it will not flood
delay(1500); // wait for a bit
digitalWrite(2, LOW); // Activate the RFID reader
}
}
}

if (code == validCode){

code and validCode are char arrays. Using the equality operator (==) on char arrays doesn't compare the contents. For that, you'll need strcmp()

Arrch: if (code == validCode){

code and validCode are char arrays. Using the equality operator (==) on char arrays doesn't compare the contents. For that, you'll need strcmp()

Note that strcmp() only works with null terminated char arrays (strings). To work with other char arrays (raw data with no null terminator) you need strncmp() and provide it the number of characters you want to compare.

thanks majenko. It worked.