warning: ISO C++ forbids comparison between pointer and integer [-fpermissive]

Guys how do I solve this I want to compare Richting[1] ( wich is a “V”) and then do something but it gives me this error “warning: ISO C++ forbids comparison between pointer and integer [-fpermissive]”.

How do I need to write my code so I can compare this in the right way ? :slight_smile:

Thanks again

Using arduino uno

#define E1 10  // Enable Pin for motor 1
#define E2 11  // Enable Pin for motor 2

#define I1 8  // Control pin 1 for motor 1 for L293D it changes the direction of the motor
#define I2 9  // Control pin 2 for motor 1 for L293D it changes the direction of the motor
#define I3 12  // Control pin 1 for motor 2 for L293D it changes the direction of the motor
#define I4 13  // Control pin 2 for motor 2 for L293D it changes the direction of the motor


char Richting[1] ;  // Direction
int Axis;                 // Numbers (the speed I want to set on the motors)
const byte numChars = 32;
char receivedChars[numChars]; // an array to store the received data
boolean newData = false;

void setup() {

  Serial.begin(2400);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(13, OUTPUT);
  pinMode(E1, OUTPUT);
  pinMode(E2, OUTPUT);

  pinMode(I1, OUTPUT);
  pinMode(I2, OUTPUT);
  pinMode(I3, OUTPUT);
  pinMode(I4, OUTPUT);
  Serial.println("<Arduino is ready>");
}

void loop() {
  if (recievedMessage())
  {
    parseMessage();
    Calculation();
    showNewMessage();
  }
}

bool recievedMessage() {
  static byte ndx = 0;
  char endMarker = '\n';
  char rc;


  while (Serial.available() > 0 && newData == false) {
    rc = Serial.read();

    if (rc != endMarker) {
      receivedChars[ndx] = rc;
      ndx++;
      if (ndx >= numChars) {
        ndx = numChars - 1;
      }
    }
    else {
      receivedChars[ndx] = '\0'; // terminate the string
      ndx = 0;
      newData = true;
      return true;
    }
  }
  return false;
}

void showNewMessage() {
  if (newData == true) {
    newData = false;
    Serial.println(Richting[1]);
  }
}

void parseMessage()
{

  strtok(receivedChars, ",");
  strcpy(Richting, receivedChars);
  Axis = atoi(strtok(NULL, ","));
}

void Calculation()
{
  if (Richting[1] == "A") {
    digitalWrite(3, HIGH);
    analogWrite(E1, Axis * 2);
    analogWrite(E2, Axis * 2);
    digitalWrite(I1, HIGH);
    digitalWrite(I2, LOW);
    digitalWrite(I3, HIGH);
    digitalWrite(I4, LOW);
  }
  else {
    digitalWrite(3, LOW);
    digitalWrite(I1, LOW);
    digitalWrite(I2, HIGH);
    digitalWrite(I3, LOW);
    digitalWrite(I4, HIGH);
  }

  if (Richting[1] == "V") {
    digitalWrite(2, HIGH);
    analogWrite(E1, Axis * 2);
    analogWrite(E2, Axis * 2);
    digitalWrite(I1, LOW);
    digitalWrite(I2, HIGH);
    digitalWrite(I3, LOW);
    digitalWrite(I4, HIGH);
  }
  else {
    digitalWrite(2, LOW);
    digitalWrite(I1, HIGH);
    digitalWrite(I2, LOW);
    digitalWrite(I3, HIGH);
    digitalWrite(I4, LOW);
  }
}
char Richting[1] ;  // Direction

Why do I keep seeing this? Who is teaching 1 element arrays? How is that even remotely useful?

Serial.println(Richting[1]);

You defined Richting to only have one element. That element is Richting[0]. There is no Richting[1]. That is pulling from whatever the compiler put into memory after Richting.

if (Richting[1] == "A") {

Again, there is no Richting[1] so this doesn't make sense.

But there's another problem. You are comparing to a one letter string, again a wasteful concept. BY using double quotes it is a string, a pointer to a char array containing one character A and a null terminator. If you want to compare to the character A then use single quotes to denote it as a character. 'A'

Thanks for responding , I know that is wrong but I don't have enough knowledge to solve this.

How can I solve this ?

Well, first a one element array doesn’t have any elements which indices greater than zero.
Second, compare a char variable with a char literal.if (Richting[0] == 'A') {

And then ask yourself what advantages a single element array brings to your sketch.

MrKrabs:
Thanks for responding , I know that is wrong but I don’t have enough knowledge to solve this.

How can I solve this ?

What part don’t you understand? You have a 1 element array. If I were you I would change that to just a char variable and leave the whole array thing off of it. Or you could start referencing Richting[0] which actually exists instead of Richting[1] in the code. The choice is yours. Is there some part of that which is confusing you?

Or was it the part about single quotes vs double quotes? The single quote key is the same as the double quote key on the keyboard except you don’t press shift key. Go put those ’ around the A instead of ". What’s hard to understand about that?

If you’ll tell me what part confuses you I can help. But I’m not going to just write your code for you.