[NEWBIE] Stupid Newbie strcmp question

From: Brian (brian@imi-bottling.com)
Date: 01/16/99

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?

The above didn't work until I added the NOT (!) in front of the
str_cmp.  If my arg matched the arg of "warriors", it would just go past
that logic, because it was FALSE.

Looking at two C books explains that it uses a compare and if it
matches, returns a 0 (zero).  Obviously 0 is FALSE.

The description it gives in the book, gives the explanation that if the
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"?

Confusing....  Perhaps I need a few new C books...

- brian

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |

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