Mail Archives: djgpp/1999/07/04/18:17:16
Al Morgan wrote:
> The function you need in strcmp(char *str1, char *str2); It returns 0 if
> both strings are equal (counter intuitive, isn't it?).
I find it helps to think of it as subtraction. i.e. strcmp(s1, s2) <=>
(s1 - s2). This also helps keep straight the meaning of the sign of the
result (which one is greater), in the rare instances where one cares.
I personally prefer to write `if (strcmp(s1, s2) == 0) ...' instead of
`if (!strcmp(s1, s2))' for this reason, since it helps me think of
strcmp as an arithmetic rather than logical operation. Even though it
is a few more bytes.
--
Nate Eldredge
nate AT cartsys DOT com
- Raw text -