Strange problem with argv in if statement

advertisements

I'm having problems with argv in an if statement in one of my C programs. I know I must be missing something simple and stupid (it's been a while since I've done anything in C). Problem is, it won't doOtherStuff() if I specify nothing else on the command line. Even if I do ./a.out -i it still runs doStuff(). Does anyone see what might be missing here? Thank you a lot in advance!

int main(int argc, char *argv[])

    if(argv[1] == "-a" || "-A")
    {
       doStuff();
    }
    else
    {
        doOtherStuff();
    }
}


If you want to compare strings in C you have to use methods like strcmp: http://www.cplusplus.com/reference/cstring/strcmp/

In C a string is actually an array of characters, so you are comparing the memory address of the 2 arrays (which will be different of course since they are different arrays).