Problems With The Code
- islower() checks if a character is lower case or not. It does not work with C-strings.
- str[size] indexes out of the buffer, you are reading memory garbage, hence the value read is undetermined.
- combining #1 and #2 it's easy to see that islower called with memory garbage as an argument yields undetermined results (can be either true or false)
- printf("%s is lowercase letter\n",str) message talks about a letter, but the argument is a C-string (series of letters). So which one are you after? Checking the whole string or just one letter (which one?)
- if islower() returns false, it doesn't mean letter is upper case. It can be a number, space, a special character or anything else.
A Proposed Fix
I think you were looking to check if the whole string is all lower case or not (again, your comments throughout the code is confusing which one you're after). For checking this, I'd have the following code snippet:
char str = "Hello World"; // = "helloworld"
char * ch = str;
while (*ch != '\0' && islower(*ch))
printf("%sll the characters are lower case in %s\n", *ch == '\0' ? "A" : "Not a", str);
The main thing is that we start iterating through all the characters via the ch pointer and checking if
- we have reached the end of the string (terminating zero, i.e. '\0') OR
- the observed character is not lower case anymore.
If, after leaving the loop, the character pointed by ch is indeed the terminating zero, then we reached the end of the string and all of them were lower case letters.
I hope this helps.