>>return *(--s1) - *(--s2);
That may give you the wrong result. It should be
return *s1 - *s2; There are four possible return values
- If *s1 is '\0' and *s2 is not, then the return value will be some negative value.
- If *s1 is NOT '\0' but s2 is, then the return value will be some positive value
- If both *s1 and *s2 are '\0' then the return result will be 0.
- If neither *s1 nor *s2 is '\0' then the return value could be either positive or negative, depending on their values.
In either event, decrementing s1 and s2 before the subtraction may (and most probably will) produce the wrong result because s1 and s2 will not be pointer to the characters that cause the previous loop to terminate.
Retired and Enjoying Life
Offline 21,961 posts
since Aug 2005