AFAIK isalpha
should return 0 on square brackets, since it is defined by the standard (§7.4.1.2.2) to
tests for any character for which isupper or islower is true, or any character that is one of a locale-specific set of alphabetic characters for which none of iscntrl, isdigit, ispunct, or isspace is true. In the "C" locale, isalpha returns true only for the characters for which isupper or islower is true.
and they shouldn't be considered uppercase or lowercase characters.
On the other hand, your
if(input[i] >='A' && input[i] <= 'z')
is wrong, since the ['A','z'] range usually includes also nonalphabetic characters, in particular, in standard ASCII, the characters [ \ ] ^ _ `
.
So, you should either split your check in two parts (to check if the character is in range ['A','Z'] or ['a','z']) or simply use isalpha
and forget about this stuff.
By the way, IIRC the standard doesn't even mandate that the ['A','Z'] and ['a','z'] ranges must be contiguous, and in facts the original EBCDIC codepage was a real mess to deal with, since to check if a character was alphabetical you couldn't check for the character to be in those ranges. Thus, to be strictly standard you can't even expect that
if((input[i] >='A' && input[i] <= 'Z') || (input[i] >='a' && input[i] <= 'z'))
will work as you expect.
Long story short: if it's not just for homework, use isalpha
, which is guaranteed to work whichever strange codepage your platform uses.