1

I want to compare two strings:

The first string is declared above my main:

char _newState[] = "AVAILABLE";

When I want to compare with a const string, i put the line:

if(strcmppgm2ram((const char *) "AVAILABLE", _newState ) == 0){
    code:
}

The function never returns a zero, what is the solution and the right typecast? strcmp is the same problem!

2 Answers 2

6

It looks like you have your parameters in the wrong order. According to the C18 library manual the signature for strcmppgm2ram is

signed char strcmppgm2ram(const char * str1, const rom char * str2 );

So your strng constant should be the second string and your character array should be the first parameter.

You should not use casts as all they do is hide issues like this. If you have a type mismatch then you should use that information to determine what the correct type should be and whether you have made a mistake. Using a cast is like telling the compiler to ignore what you've done even if the compiler thinks it should be a warning/error.

Sign up to request clarification or add additional context in comments.

1 Comment

@user1466676: You're welcome. Please remember to accept the answer if it answered your question to your satisfaction.
2

Try:

const far rom char _newState[] = "AVAILABLE";

For future reference it's a good idea not to ignore compiler warnings - they are there to help you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.