strcmp() & if() & else if() Help

Hey all! I’ll keep this short, sweet, and to the point.

While trying to clean up the code for a project I’m working on, I was made aware of the fact that I can remove a couple of variables and save some RAM by using the strcmp() function. The gist is I was taking a char array, turning it into a string, then comparing the two strings using

char myChar = [long messy function to grab user input];
String stringOne = myChar myChar;
if (stringOne == "something") 
{
  if (stringTwo == "something") {...}
} 
else if (stringOne == "something else") {...}

While this worked fine, it is a memory hog because it’s not just stringOne, it’s up to stringFour. Someone on reddit mentioned I could do away with stringOne etc. and use strcmp(), which does function. For one level of the command input I’m building. When I change it to

char myChar = [user input]
if (strcmp(stringOne, "something")) {...} 
else if (strcmp(stringOne, "something else")) {...}

I get the error of “else statement without previous if” when I attempt to compile.

So in my first example the user input would be something like <part1/part2/part3/part4>. I have a function that reads the stuff between “<>” and breaks it into separate pieces at the “/”. If I remove all the “else” statements and leave them as plain “if” statements my program will compile, however if any command is entered it will run every single command. If I leave the “else” it fails to compile.

Does anyone know why this is and what I should do to fix it? Should I just stick with my original method that works but uses unnecessary memory?

error: "else statement without previous if" happens when you have an ill-form statement like:

if (true); {

} else{

}

Also, strcmp() expects two cstring (null terminated char array) and not String object.
Also 2, strcmp() return 0 when the two cstrings are equal. And 0 is interpreted as false.

@arduino_new replied while I was writing this, but there is a bit of additional information so I'll post it anyway:

Please post your actual code.

Note that strcmp returns 0 when the two strings are identical. So the code in your if and else if blocks will only execute when the strings don't match. Even if that's what you intended, I think it's not best practices to treat strcmp as if it returns a boolean. The logical assumption would be that strcmp returns true when the strings match, but this is not how it works. So it's more clear to do an explicit comparison:

if (strcmp(stringOne, "something") != 0) {  // the strings don't match

or:

if (strcmp(stringOne, "something") == 0) {  // the strings match

Reference:
http://www.cplusplus.com/reference/cstring/strcmp/