From the cppreference.com documentation
int strcmp( const char *lhs, const char *rhs );Return value
Negative value if lhs appears before rhs in lexicographical order.
Zero if lhs and rhs compare equal.
Positive value if lhs appears after rhs in lexicographical order.
As you can see it just says negative, zero or positive. You can't count on anything else.
The site you linked isn't incorrect. It tells you that the return value is < 0, == 0 or > 0 and it gives an example and shows it's output. It doesn't tell the output should be 111.
Videos
From the cppreference.com documentation
int strcmp( const char *lhs, const char *rhs );Return value
Negative value if lhs appears before rhs in lexicographical order.
Zero if lhs and rhs compare equal.
Positive value if lhs appears after rhs in lexicographical order.
As you can see it just says negative, zero or positive. You can't count on anything else.
The site you linked isn't incorrect. It tells you that the return value is < 0, == 0 or > 0 and it gives an example and shows it's output. It doesn't tell the output should be 111.
To quote the man page:
The strcmp() and strncmp() functions return an integer less than, equal to, or greater than zero if s1 (or the first n bytes thereof) is found, respectively, to be less than, to match, or be greater than s2.
In other words, you should never rely on the exact return value of strcmp (other than 0, of course). The only guarantee is that the return value will be negative if the first string is "smaller", positive if the first string is "bigger" or 0 if they are equal. The same inputs may generate different results on different platforms with different implementations of strcmp.
1) K&R are comparing the ascii values of those chars, that's why you get 32 and -12, check out an ascii table and you'll understand.
2)If you don't check for \0 , how can you know when the string end? That's the c strings terminator.
Capital letters in terms of ASCII codes actually precede lowercase letters, as you can see here.
So in terms of lexicographic ordering, s1 is treated as being bigger than s2, because the ascii value of the first letter that differs is the larger one.
Well, if it's
char pch[64];
then you can't have 64 visible characters in there, since the last entry is needed for the termination. If you do have "file111111111111111111111111111111111111111111111111111111111111" in that array, it's not terminated and calling strcmp() on it invokes undefined behavior.
Also, as a minor point, saying that strcmp() returns "false" is wrong, since its return is not boolean. It returns the relation between the two first differing characters; if no characters differ the strings are equal, then it returns zero.
If one or both your arrays have an exact size of 64, you are missing the final '\0' ending the string.