argv does not equal string (char*)
-
I am using the command line to pass values. The values are numbers or "ni" for negative infinity (& pi for positive). This is my code:
if (argv[1] == "ni")
// do somethingBut it fails. It never evaluates to true :wtf:. Why is this? "ni" is a char array and so is argv[], is it just me or is something going on. I tried this on Windows and Unix and the same thing happened. Download here[^] for the full source
-
I am using the command line to pass values. The values are numbers or "ni" for negative infinity (& pi for positive). This is my code:
if (argv[1] == "ni")
// do somethingBut it fails. It never evaluates to true :wtf:. Why is this? "ni" is a char array and so is argv[], is it just me or is something going on. I tried this on Windows and Unix and the same thing happened. Download here[^] for the full source
That's not how you compare C-style strings. Use
strcmp()
instead.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?
-
That's not how you compare C-style strings. Use
strcmp()
instead.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?
yes, i fixed the problem. I just converted to string. I forgot that C-strings are just pointers, so you are actually comparing the memory locations. However, i could have sworn i had seen it written before (unless it was to specifically compare memory locations)
Customer in computer shop: "Can you copy the Internet onto this disk for me?"