I wrote a function that compares the characters of two strings recursively. If the characters of the strings are all equal the function returns 0. If the character from string1 is smaller ie-"a" to "l" it returns the negative difference of their ASCII vaules. If the character from string2 is larger ie-"l" to "a" it returns the positive difference of their ASCII vaules. I can see that my code will stop when two different characters are reached, but a zero is always returned. The code:
int str_compare(const char *str1, const char *str2)
{
if (*str1 != '\0' || *str2 != '\0')
{
if (*str1 != *str2)
{
if (*str1 > *str2)
{
cout << "str1= " << str1 << " " << "str2= " << str2 << endl;
return *str1 - *str2;
}
else if (*str1 < *str2)
{
cout << "str1 " << str1 << " " << "str2 " << str2 << endl;
return *str1 - *str2;
}
}
str_compare(str1 + 1, str2 + 1);
else return 0;
}