-4

I'm using this code to test the entry from the command line when executing the program .. It's not working. What should I do ???? ?

if(argc >1)
    {
        if (argv[1]  == "b" || argv[1]  == "B")
                {b =1;}
        else if (argv[1]  == "h" || argv[1]  == "H")
                { b = 0;}
    }
    else 
        { b =0; }
4

1 に答える 1

2

You can not compare c strings using == operator. Use strcmp instead. For example -

if ( (0 == strcmp(argv[1], "b") ||  .... )
于 2013-09-23T23:28:45.063 に答える