I'm learning C and I've came around a strange problem. I think I understand the difference between multiple ifs and else-if statement, but I simply can not understand the difference in behavior this time. If I delete the else keyword it works as intended, but with else on it does not.
The code is about counting of occurrences of each letter without differentiating lower case or upper case (so 'a' and 'A' both counts as 1 occurrence for letter 'a').
I've tried omitting braces where I could but nothings changed so I've left them in to avoid caveats.
while ((c = getchar()) != EOF)
{
if ('A' < c < 'Z')
{
++array[c - 'A'];
}
else if ('a' < c < 'z')
{
++array[c - 'a'];
}
}
When I type in 'a' then the array is not being incremented, but if I delete the else statement thus switching to a multiple if situation, it works as intended. Letter 'A' updates the array nicely in both cases.
Could you please help me understand the difference in behavior in this case?