Semantics of Equals (was: Re: Question about checks for min and max values)

Kenneth Brody kenbrody at bestweb.net
Mon Jul 25 14:06:32 PDT 2005


Quoting Fairlight (Mon, 25 Jul 2005 16:53:11 -0400):

> Y'all catch dis heeyah?  Kenneth Brody been jivin' 'bout like:
> > #include <stdio.h>
> >
> > int main(int argc, char *argv[])
> >     {
> >     char string1[] = "This is a string";
> >     char string2[] = "This is a string";
> >
> >     if ( string1 == string2 )
> >         printf("They are equal.\n");
> >     else
> >         printf("They are not equal.\n");
> >
> >     return(0);
> >     }
>
> Maybe the smiley is the key, but that only works because they're exactly
> identical--assuming it works.  One should be using strcasecmp() for
> strings.

I guess it depends on your definition of "works".

The output is "They are not equal."  Yes, strcmp() will say that they
compare equal, but "==" will not.

On the other hand, given:

    int num1 = atoi("0");
    int num2 = atoi("");

the expression:

    num1 == num2

will be true.

:-)

--
KenBrody at BestWeb dot net        spamtrap: <g8ymh8uf001 at sneakemail.com>
http://www.hvcomputer.com
http://www.fileProPlus.com


More information about the Filepro-list mailing list