Array and if statement syntax

I have problem with char array and if statement.

i try to do:

void Motors::manualMotion(int CycleDutyAzim,int CycleDutyPitch,char directionAzim[],char directionPitch[]){


    setCycleDutyA(CycleDutyAzim);
    setCycleDutyP(CycleDutyPitch);

    if(directionAzim=="FORW"){
        moveForwAzim();
    }else if(directionAzim=="BACK"){
        moveBackAzim();
    }else{
        Serial.println("FAIL");
        handbreakAzim();
    }

    if(directionPitch=="FORW"){
        moveForwPitch();
    }else if(directionPitch=="BACK"){
        moveBackPitch();
    }else{
        Serial.println("FAILED");
        handbreakPitch();
    }
}

I get all the time the serial.prints with the messages. I made it work with on char not an array. What is the syntax in order to work properly.When i call the method i give this:

Motors::manualMotion(90,50,"FORW","BACK");

It does not work.When i use one char like F and B, it works properly.
i also used instead of " " the ' '

if(directionAzim=="FORW"){
if (strcmp (directionAzim, "FORW") == 0) {
Motors::manualMotion(90,50,"FORW","BACK");

You are using char arrays that are not null terminated.

You can either create two constant char arrays or for more flexibility use char pointers.

         const char FORW[5] = "FORW";
         const char BACK[5] = "BAKW";  // note [5] to include /0

         const char *FORWARD = "Forward";
         const char *BACKWARD = "backward";

stringer:

Motors::manualMotion(90,50,"FORW","BACK");

You are using char arrays that are not null terminated.

Where?

Those string constants, "FORW" and "BACK" both get compiled with terminating NULLs.

He was trying to use the wrong operation ( == ) to test equality of char arrays that will work when testing the equality of char variables is all.

^ Yes you are correct. My post was in addition to your fix.

However, I think it is still best practice to use defined constants and char* for flexibilty.

However, I think it is still best practice to use defined constants and char* for flexibilty.

better still is to put them in PROGMEM, and save precious RAM.

stringer:
^ Yes you are correct. My post was in addition to your fix.

However, I think it is still best practice to use defined constants and char* for flexibilty.

While I am a pointer user and just love the things, the string array name -is- a const char *.

Where the char * comes in handy in his code is the function args, he could have just 1 function for both Azimuth and both Pitch moves which would shorten and simplify his code. But I wouldn't make a pointer just to set to a constant string and then pass that to the function when simply passing the array name would do. I might use a small array of pointers and an algorithm to choose which to pass but I'd want a wider set of choices or some possibility of that before going to the trouble.

Hi AWOL, don't const char string arrays stay in PROGMEM anyway? I thought that was told.

Hi AWOL, don't const char string arrays stay in PROGMEM anyway?

Nope.