How to properly compare command-line arguments?

In your code, argv[1] == "-s" is the erroneous part. comparison of strings cannot be done with == operator.

To compare strings, you need to use strcmp().

Your code should look like

if ( ! strcmp(argv[1], "-s")) { //code here }

if you want to check if argv[1] contains "-s" or not.


Compare the two strings using the strcmp(s1,s2) function.

            if (strcmp(argv[1],"-s")==0)
                    girls();  //Prints "Girls"
            else if(strcmp(argv[1],"-k")==0)
                    boys();   //Prints "Boys"
            else
                    printf("OMG!!");

if you check the argv[1] == "-s" the condition will not be true. since it is a string you can use the strcmp function.

     if(( strcmp(argv[1],"-s")) == 0)
     girls();
     else if ((strcmp(argv[1],"-k")) == 0)
     boys();

Try this..