Mark McIntyre said:
On Sat, 16 Apr 2005 11:12:35 GMT, in comp.lang.c , Keith Thompson
Actually you don't, but I'm sure you can work out why.
I'm sure you could do something equivalent to strcmp(), but since
strcmp() does *exactly* what's needed in this case, why bother?
which is almost certainly what you want, when you think about it.
I've thought about it, and it's almost certainly not what's wanted.
The OP's (incorrect) code was:
char depend[] = "-depend";
if (argv[1] != depend)
[...]
He clearly wanted to check whether the first argument to the program
was exactly equal (in the string comparison sense) to "-depend".
Slightly OT:
On the systems I use, and on all Unix-like systems (and probably on
Windows systems as well), invoking the program as
progname -depend foobar
will cause argv[0] to point to some representation of the name of the
program, argv[1] to point to "-depend", and argv[2] to point to
"foobar" (with argc==3). There will be no spaces in any of the
arguments unless the user goes out of his way to put them there.
Are you expecting argv[1] to point to "-depend foobar"? It almost
certainly won't (and if it does it should probably be flagged as an
error).
Admittedly the standard says very little about how command line
information is tranformed to argc and argv, but regardless of any
system-specific considerations, the OP was clearly trying to check for
the exact string "-depend", no more, no less, no trailing spaces.
Checking for a space at the end of the string doesn't change it?
I honestly don't understand what you're trying to say. Am I
missing something here?