I was wondering tht the normal way of doing things is, if some test passes then the value is true. Say for e.g if u use functions like isalpha() or isdigit() etc.. then the value returned is true if the character is an alphabet or a digit...
Y then string functions like strcmp(s1, s2) return true if the strings are not equal? I keep wondering y they designed the string functions like that?
Why? I don't know, but I think with strcmp(), the 'true' value is 0, so it may imply that there are 0 differences between the first and second string, but they're the only ones I know of which do that.
>Y then string functions like strcmp(s1, s2) return true if the strings are not equal?
They don't. They return one of three values depending on the relationship between the two strings. The value is negative if the first string is lexographically less than the second, 0 if the strings are equal, and positive if the first string is lexographically greater than the second. The result does not represent a boolean value, so thinking in terms of true and false will only confuse you.
Mind you, strcmp() returns one of 3 possible values. It doesn't test only for one of two.
int result = strcmp(string str1, string str2);
if str1 less than str2, returns a negative value
if str1 = str2, returns 0
if str1 > str2, returns a positive value
Now, if you look at similar functions that return one of three possible values, you will find that the same convention follows. And also, they don't return bool, for the obvious reasons.
Thanks . solves my problem...