sorry HELP!!!! again

sorry i just have another question.....

when you have something stored in a char* word.... say the words Oct ...

now you want to compare this...

if(word = 'Oct')
{
prinf("YEY");
}
... this doesn't work... why? and how can i rectify it... i get the warning "makes integer from pointer without cast"... i tried casting it but that still doesn't work...

please help
thank you in advance
Krystle

Comments

  • First of all use '==' for testing values, '=' is for assigning values.

    The compiler give this error because what you are trying to do is assign word with 'Oct' (also in C strings are in " "'s). The way you test if strings are the same in C is like this

    [code]
    #include

    int main(void) {
    if(!strcmp(word,"Oct")) {
    // word == "Oct"
    } else {
    // word != "Oct"
    }
    return(0);
    }
    [/code]

    Also notice that strcmp will return false when a string matches so you have to ! it to make it work the way you want. Why cant there be any order in the world ay :P
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories