Re: [NEWBIE] Stupid Newbie strcmp question

From: Xual (
Date: 01/16/99

On Sat, 16 Jan 1999, Brian wrote:

> Given the following example:
>   if (!str_cmp("warriors", arg)) {
>     sprintf(buf, "Warrior Guild -- Arg: %s\r\n", arg);
>     send_to_char (buf, ch);
> }
> I was under the assumption that strcmp and str_cmp returned TRUE when
> the two strings matched.  Is this not true?

No, strcpmp() and related functions return FALSE if the strings are the
same.  The example above is correct.

> first arg is smaller than the 2nd, it produces a "less than 0" response
> and if arg1 is greater than arg2 it produces a "greater than 0" response
> (which I guess would be 1, which would be TRUE). However, this seems to
> indicate numeric variables and we're comparing alpha characters.... How
> does strcmp work then?  Will strcmp always read FALSE on a comparison
> that's equal?  And is there any possible way that a comparison between
> alpha strings can be "less than zero"?

Anything other that 0 is TRUE, including -1.  The prototype for strcmp()
looks something
like this:

int strcmp(const char *s1, const char *s2);

Which means it returns an int, depending on how the strings compare.

"Misery is boundless"
        -Xual the Torturer, on the Eve of the Sundering.

Danathara Online RPG

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  |

This archive was generated by hypermail 2b30 : 12/15/00 PST