How to create program in C that can use parameters?

5

I'm studying C, and now trying to pass parameters. Well, although I'm thinking I got it, it's giving me an error when I try to use that variable ...

I need to compare the "argument_value" char to make decisions in the program!

What can I be doing wrong?

int main (int argument_count, char *argument_value[]) {

            printf("\n");
            printf("\nargument_value[0]  : %s", argument_value[0]);
            printf("\nargument_value[1]  :   %s", argument_value[1]);
            printf("\nargument_value[2]  :   %s", argument_value[2]);

            printf("\n");
            if      (argument_value[1] == "detailed"){printf("\n detalllll");}
            else if (argument_value[1] == "hexa")    {printf("\n hexaaaaaa");}
            else if (argument_value[1] == "bits")    {printf("\n bitsssss");}
            else                                     {printf("\n none...");}



}

This code always returns me the parameters that pass in the command line, and "none ..."

    
asked by anonymous 04.10.2016 / 04:26

1 answer

5

Configuring this SOpt response :

To compare strings in C, use the strcmp function.

Example:

if (strcmp(argument_value[1], "detailed") == 0) {printf("\n detalllll");}
    
04.10.2016 / 04:52