-   Programming (
-   -   C Arguments to main - can't compare values (

madsovenielsen 07-24-2011 05:42 PM

C Arguments to main - can't compare values
Whats wrong with this:

#include <stdio.h>

int main(int argc, char *argv[])
    if(argv[4] == "-verbose")
        printf("Verbose is on");

  return 0;

I can use argv[4] in printf() just fine. But i can't compare the content of argv[] to anything.

Why ?

Kind regards Mads Nielsen

toredo 07-24-2011 05:46 PM

You have to use strcmp to compare two c-strings.

With '==' you compare in your case only the strings addresses, which here are never the same.
An you should always check the parameters-count (argc).

best regards

madsovenielsen 07-25-2011 07:17 AM

Thank you very much!

All times are GMT -5. The time now is 10:00 AM.