I have the following code:
#include <stdio.h>
#include <ctype.h>
int main(int argc, char **argv)
{
int ch, lower, upper = 0;
printf("Enter a line of text: \n");
while ((ch = getchar()) != EOF) {
if (islower(ch)) {
ch = toupper(ch);
++upper;
} else if (isupper(ch)) {
ch = tolower(ch);
printf("Looking at lower: %d\n", lower);
++lower;
printf("Looking at lower: %d\n", lower);
}
putchar(ch);
}
printf("Hello\n");
printf("\nRead %d characters in total. %d converted to upper-case, %d to lower-case.", upper+lower, upper, lower);
}
For some reason the upper variable is being set correctly, but can't work out why lower is giving an erroneous value. E.g. If I type in 'Football' it says 4195825 converted to lower-case, where the actual output should be 1.
I can't see where I'm going wrong here.