Help with CHAR please

Hello

I have a menu in which I can select some words rather than numbers. I was thinking of using a simple in-between step of converting a string into a number. For instance, Clockwise == 0, CounterClockwise == 1 etc. But I'm doing something wrong. I was trying to get this done using the piece of coe below, but that doesn't work. If I Serial.print(SomeWord); than it will spit out 'hello'. I assumed that because it knows the word-value of SomeWord, I could use that to change another integer to a number.

Is this not possible?

  char SomeWord[]="hello";



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

void loop() {
  
  if  (SomeWord == "hello") {
    Serial.println("Correct");}
   else Serial.println("Not Correct");
  
}
if  (SomeWord == "hello")

You can't compare a whole array at once like that. Have a look at the strcmp function to compare strings.

I’ve fixed it using ‘String’… which I started with but change to ‘Char’ later…

This works like a charm:

  String SomeWord="hello";



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

void loop() {
  
  if  (SomeWord == "hello") {
    Serial.println("Correct");}
   else Serial.println("Not Correct");
  
}

Now I can swap text for numbers in the menu and use them allover my sketch.

Thanks Delta_G

No real need to thank Delta_G for because you didn't use his solution...

And because of all snags of String I would use strcmp().

if(!strcmp(SomeWord, "hello")

snewpers: This works like a charm

I've never really understood that simile - a charm is a superstition or magic, so at best can only "work" 50% of the time.

AWOL: I've never really understood that simile - a charm is a superstition or magic, so at best can only "work" 50% of the time.

Well he did use the String class to fix it. So it might be an apt comparison in this case.

uh... I've changed it to strcmp(), so yeah, thank you Delta.

'Works like a charm' is a mid-1800s verb phrase 'To achieve the objective with perfect success'.

I'll never use it again to avoid confusion :)