ISO C++ forbids comparison between pointer and integer

Hi there,

I've got a problem with if-statements:

My problem: I want to compare values from an array to predefined values so that I can print a special message for every case. My code:

x=Str1[8], HEX;
    y=Str1[7], HEX;
    z=Str1[6], HEX;
    a=Str1[5], HEX;
    
    if(x=="5D" && y=="92" && z=='C6' && a=='42')
    {lcd.print("xxx");}

The values themselves are from an array that is filled earlier. When I try to compile my code it says: "ISO C++ forbids comparison between pointer and integer" How can I realize that comparison?

Thanks in advance.
arduino2013

x=Str1[8], HEX;

This is NOT doing what you think it is. Loose the , HEX crap.

My problem: I want to compare values from an array

It would be good to know what kind of array.

If the array is a char array, then no element in the array can hold "5D". An element might, depending on the array type, hold '5D'.

I suggest that you head over to http://snippets-r-us.com for help with your snippets.

Hi PaulS,

it's an int array.

Thanks for your help.

You are assigning with the value of HEX in all cases.

Making up your own language is never a good idea.

An int can never be "5D". use 0x5D as a constant.

An int can never be "5D". use 0x5D as a constant.

For better understanding my problem here's my full code:

include <SoftwareSerial.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(6, 9, 5, 1, 3, 0);
SoftwareSerial rfid(7, 8);
SoftwareSerial xbee(10, 9);

//Prototypes
void check_for_notag(void);
void halt(void);
void parse(void);
void print_serial(void);
void read_serial(void);
void seek(void);
void set_flag(void);

//Global var
int flag = 0;
int Str1[11];
char x;
char y;
char z;
char a;

//INIT
void setup()
{
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("   Wilkommen!");
  xbee.begin(9600);
  rfid.begin(19200);
  delay(10);
  halt();
 
}

//MAIN
void loop()
{
  read_serial();
}

void check_for_notag()
{
  seek();
  delay(10);
  parse();
  set_flag();

  if(flag = 1){
    seek();
    delay(10);
    parse();
  }
}

void halt()
{
 //Halt tag
  rfid.write((uint8_t)255);
  rfid.write((uint8_t)0);
  rfid.write((uint8_t)1);
  rfid.write((uint8_t)147);
  rfid.write((uint8_t)148);
}

void parse()
{
  while(rfid.available()){
    if(rfid.read() == 255){
      for(int i=1;i<11;i++){
        Str1[i]= rfid.read();
      }
    }
  }
 
  if(!rfid.available()) {lcd.setCursor(0,1); lcd.print("Chip auflegen");}
}

void print_serial()
{
  if(flag == 1){
    //print to serial port
    lcd.setCursor(0, 1);
    x=Str1[8];
    y=Str1[7];
    z=Str1[6];
    a=Str1[5];
    
    if(x=="5D" && y=="92" && z=='C6' && a=='42')
    {lcd.print("xxx");}
    
    //lcd.print(Str1[8], HEX);
    //lcd.print(Str1[7], HEX);
    //lcd.print(Str1[6], HEX);
    //lcd.print(Str1[5], HEX);
    //lcd.print("               ");
    
    delay(1000); //
    check_for_notag();
  }
}

void read_serial()
{
  seek();
  delay(10);
  parse();
  set_flag();
  print_serial();
  delay(100);
}

void seek()
{
  //search for RFID tag
  rfid.write((uint8_t)255);
  rfid.write((uint8_t)0);
  rfid.write((uint8_t)1);
  rfid.write((uint8_t)130);
  rfid.write((uint8_t)131);
  delay(10);
}

void set_flag()
{
  if(Str1[2] == 6){
    flag++;
  }
  if(Str1[2] == 2){
    flag = 0;
  }
}
if(x==0x5D && y==0x92 && z==0xC6 && a==0x42)

P.S. Call your variables sensible names - single letter names are useless in describing what is going on.

P.S. Furthermore, x,y,z,a are all only used in one function, so why waste memory, make them local.

Unfortunately it only shows the Tag-ID only executes the following part:

lcd.print(Str1[8], HEX);
    lcd.print(Str1[7], HEX);
    lcd.print(Str1[6], HEX);
    lcd.print(Str1[5], HEX);
    lcd.print("               ");

Why is that and how to resolve it?

Thanks for your help, Tom. I replaced my if-statement by yours but it only shows the Tag-ID.

An int can never be "5D".

But an "int" can be 'SD', interestingly.

In which case one or all of the following are not true:
x==0x5D
y==0x92
z==0xC6
a==0x42

What exactly does this:
lcd.print(Str1[8], HEX);
lcd.print(Str1[7], HEX);
lcd.print(Str1[6], HEX);
lcd.print(Str1[5], HEX);

display on the LCD?

Hi Tom,

it displays: 5D92C642.

What exactly does this:
lcd.print(Str1[8], HEX);
lcd.print(Str1[7], HEX);
lcd.print(Str1[6], HEX);
lcd.print(Str1[5], HEX);

display on the LCD?

was a rhetoric question. It was designed to make you THINK about what you are doing vs. what you are seeing. Str1[n] contains a value. You are printing that value to the LCD using a specific method with specific arguments.

You should experiment with different values for those arguments to see what affect that has on the output. For instance, use DEC, OCT, and BIN as the second argument. Then, for giggles, use 7 as the second argument.

Note that in all cases, WHAT is being printed has not changed. The result has though. Do you know why?

When you do, then you can understand why your questions in this whole thread make no sense.

I can see that the result was converted into the specified number system. But how does that affect my plan to compare it to a special value and print a special text?

But how does that affect my plan to compare it to a special value and print a special text?

The VALUE never changed. The output representation did.

if(Str[8] == 0x5D)
{
   // Do something when Str[8] contains 0x5D
}
if(Str[8] == 0x5D)

The VALUE never changed. The output representation did.

But isn't that 0x5D wrong then? I tried the following:

if(x==93 && y==142 && z==185 && a==66)
    {lcd.setCursor(0,1);
    lcd.print("xxx");}

but it didn't work either. Why is that?

because you are getting twisted up between strings and integers.

str[8] is a character, like '5' or 'D', it cannot be "5D" because that is two characters. To convert you would need to do something like

x = convert_chars_to_byte(str[8]) + 16 * convert_chars_to_byte(str[7]);

Hi KeithRB,

+ 16 * convert_chars_to_byte(str[7])

So can I sum up all the str[x]? And for what does "+ 16*" stand for?

Thanks

Hi KeithRB,

unfortunately your code doesn't work. It says "rfid_aktuell.ino: In function 'void print_serial()':
rfid_aktuell:110: error: 'str' was not declared in this scope
rfid_aktuell:110: error: 'convert_chars_to_byte' was not declared in this scope" and doesn't compile. What's that?

str[8] is a character,

First, it's Str, not str. Second, Str is an array of ints. Pay attention.