(SOLVED)Help with ISO C++ forbids comparison between pointer and integer.

Hello again.

Can anyone help me with this error ISO C++ forbids comparison between pointer and integer because for the love of god i can't work it out.

#define Ign_Mon 4

byte Ignition_Monitor()
{
  if(digitalRead(Ign_Mon) == LOW)
  {
    return 1; //Ignition is turned on.
  }
  else
  {
    return 0; //Ignition is turned off.
  }
}

void setup() {
  // put your setup code here, to run once:
  pinMode(Ign_Mon, INPUT_PULLUP);
  if(Ignition_Monitor == 1)
  {
    //Do something.
  }
  else
  {
    //Do something else.
  }
}

void loop() {
  // put your main code here, to run repeatedly: 
  
}

Many thanks.

You are trying to compare the result of a function to a number. This means you need to actually call the function first

if(Ignition_Monitor() == 1)

This line

  if(Ignition_Monitor == 1)

Is comparing the address of the function to 1. You probably mean this

  if(Ignition_Monitor() == 1)

which compares the result returned by the function to 1

God dam it =(, thank you very much. I should have seen that i was missing the () of Ignition_Monitor. Bit embarrassed now asking for help with something as little and stupid as missing (), should have seen that lol. Thanks ppl.

I have a familiar problem any one can help please, I'm very smart but i'm young and cant find an answer. hear is my code

if( FLOW == 2)

void FLOW (int Flow)
{
if (digitalRead(buttonPin))
{
Flow = 1;
}

if (digitalRead(buttonPin2))
{
Flow = 2;
}
}

as much as I want to show, will show if need be.

sorry the first flow part was the part with the problem.

#include <VirtualWire.h>
int i;
void setup() {
vw_set_ptt_inverted(true);
vw_set_rx_pin(10);
vw_set_tx_pin(7);
vw_set_ptt_pin(8);
vw_setup(4000);
vw_rx_start();
unsigned int data = 0;

Serial.begin(9600); // Debugging only
}
void loop(){

byte buf[VW_MAX_MESSAGE_LEN]; // a buffer to hold the incoming messages
byte buflen = VW_MAX_MESSAGE_LEN; // the size of the message
if (vw_get_message(buf, &buflen)){ //if (vw_get_message(message, &msgLength)) // Non-blocking
{
Serial.print("Got: ");
for(i = 0; i < &buflen; i++)
{
Serial.write(buf*);*
}
Serial.println();
}
}
[/quote]
I also have the message (iso c++ forbids comparison between pointer and integer) with my code trying to read the buffer, should be fine according to: http://www.arduino.cc/en/Reference/For
Please help :slight_smile:

You are comparing an integer ( i ) with a pointer ( &buflen ), why?

Here's a simple tip; if the compiler says "C++ forbids comparison between pointer and integer", look through your code for all the places you do any comparisons. The compiler will normally narrow it down to an individual function.

AWOL:
Here's a simple tip; if the compiler says "C++ forbids comparison between pointer and integer", look through your code for all the places you do any comparisons. The compiler will normally narrow it down to an individual function.

The compiler will narrow it down to a specific line, and a specific character on that line, pin-pointing EXACTLY where the error is. One has only to actually READ the error message....

Regards,
Ray L.

The error is here: for(i = 0; i < &buflen; i++)
Well, I amnot sure why I am comparing an integer with a pointer :slight_smile:
I just copy the code from a virtualwire tutorial.
I am actually trying to figure out how virtual wire works.
So I send message from one arduino board to another and I need a code to serial print the messages one after the other... :blush:

... and thank you for the support
can anyone recommend a good book to learn Arduino C++ from scratch, considering that I know absoluting nothing about programming?

The error is here: for(i = 0; i < &buflen; i++)

Can you provide a link to where you got this code?

The address of buflen is a pointer to buflen, so the comparison with "i" is invalid.

can anyone recommend a good book to learn Arduino C++ from scratch

The first thing to do is stop referring to the language as Arduino C++. It is plain C++.

The second thing to get over is the idea that one book will be sufficient. I have half a dozen that cover various parts of the language.

ANY book on C++ is going to teach you something that you haven't seen before.

When you write &buflen, it means: the memory address of where the variable named "buflen" is stored.

Obviously you want to get the value that is stored at this address, so simply use:

for(i = 0; i < buflen; i++)

There are plenty of free programming tutorials out there. That said, if you are totally new to programming, start with a tutorial on learning C. That's good enough for a start. When you get comfortable with that, then pick a C++ tutorial and keep learning.

Thank you everybody, it works! well not exactly as I intended but that's a different problem :slight_smile: and I will try to sort it out myself before disturbing.
@AWOL, I cannot recall where I got it from, some material that I downloaded long ago, but it was probably typo as guix gave me the right solution.
@ guix special thanks :slight_smile:
@ PaulS and econjack I just thought that the Arduino Ide used a simplified version of C++, well at least now I know where to look at... everywere :slight_smile:

HI smart people

I a new member of this forum and have a similar problem with this topic. Please help.
It will be a huge favor

currently i making program to compare 2 variable to activate a condition like this

char* memberE[]={"Rendah", "Agak Rendah", "Normal", "Agak Tinggi", "Tinggi"};
char* memberDE[]={"Negatif", "Normal", "Positif"};
char* kondisiEr [1];
char* kondisiDEr [1];
float waktuIr=0;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:

kondisiEr[1] = "Rendah";
kondisiDEr[1] = "Negatif";
float mfE = 0.5;
float mfDE = 1;

if (digitalRead.kondisiEr[] == memberE[] && digitalRead.kondisiDEr []= "Negatif") { //something wrong here
waktuIr= (min(mfE ,mfDE))*5;
Serial.print ("jika error ");
Serial.print (kondisiEr[1]);
Serial.print (" dan delta error ");
Serial.print (kondisiDER[1]);
Serial.print ("maka irigasi besar selama ");
Serial.println (waktuIr);
}
else Serial.print ("kodingan salah");
}

delay (3000);
}

Arduino: 1.6.6 Hourly Build 2015/06/23 05:51 (Windows 8), Board: "Arduino Uno"

Build options changed, rebuilding all

Defuzzifikasi.ino: In function 'void loop()':
Defuzzifikasi:19: error: request for member 'kondisiEr' in 'digitalRead', which is of non-class type 'int(uint8_t) {aka int(unsigned char)}'
Defuzzifikasi:19: error: expected primary-expression before ']' token
Defuzzifikasi:19: error: expected primary-expression before ']' token
Defuzzifikasi:19: error: request for member 'kondisiDEr' in 'digitalRead', which is of non-class type 'int(uint8_t) {aka int(unsigned char)}'
Defuzzifikasi:19: error: expected primary-expression before ']' token
Defuzzifikasi:24: error: 'kondisiDER' was not declared in this scope
Defuzzifikasi.ino: At global scope:
Defuzzifikasi:31: error: expected constructor, destructor, or type conversion before '(' token
Defuzzifikasi:32: error: expected declaration before '}' token
request for member 'kondisiEr' in 'digitalRead', which is of non-class type 'int(uint8_t) {aka int(unsigned char)}'

please help
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

if (digitalRead.kondisiEr[] == memberE[] && digitalRead.kondisiDEr []= "Negatif") { //something wrong here
  1. Comparing pointers to strings is silly. The pointers are not the same. Use strcmp() to compare what is pointed to.

  2. Only you have any idea what the hell that digitalRead mess is there.

char* kondisiEr [1];
char* kondisiDEr [1];

One-element arrays. Why? Are you planning go expand them later?

 kondisiEr[1] = "Rendah";

There is no kondisiEr[1], only kondisiEr[0]. You are building on your neighbor's plot.

 kondisiDEr[1] = "Negatif";

Well, the neighbor is doing the same. (If it is that neighbor, don't know for sure without further investigation; could be another neighbor building on your plot.)

 if (digitalRead.kondisiEr[] == memberE[] && digitalRead.kondisiDEr []= "Negatif") { //something wrong here

What is this I don't even...

This is not right. This is not even wrong.

Can you explain what this line is supposed to do?