1. ## Isalpha Function Issue

In the below code, I am attempting to count the number of letters and number of words in a phrase. In researching the return values of isalpha(), I noted that when a letter is present the first character isalpha() output is 1. But the second character isalpha() output is 2? The phrase that was input into this example was the following: How do you organize? Can someone help me with why I am not getting uniform output for the "H" character and the "o" character?

Code:
```#include <stdio.h>
#include <ctype.h>

int main(void)
{
int ch;
float avg = 0;
int spaces = 0;
int letters = 0;
int test = 0;
int ltrcnt = 0;
int spccnt = 0;
while((ch = getchar()) != '\n')
{
test = isalpha(ch);
if(isalpha(ch) == 2)
{
ltrcnt++;
}
if(isspace(ch) == 8)
{
spccnt++;
}
}
printf("The Number Of Words Are %d , The Number Of Letters Are %d ",(spccnt+1),ltrcnt);

}```

2. Originally Posted by mcertini
In researching the return values of isalpha(), I noted that when a letter is present the first character isalpha() output is 1. But the second character isalpha() output is 2? The phrase that was input into this example was the following: How do you organize? Can someone help me with why I am not getting uniform output for the "H" character and the "o" character?
The return value of isalpha is either zero (false) or non-zero (true).

If you want to differentiate between uppercase and lowercase letters, use isupper and islower respectively.

laserlight,

Thank you for your reply. As you state and what I have learned from another poster:

isalpha returns zero if the given character is not an alphabet.
Returns non-zero if it is alphabet.
And may return '1' if the alphabet is of upper case, and '2' if it is lower case.

4. "another poster" has misinformed you.

There is no guarantee about what non-zero value is returned if a character is alphabetic. There is certainly no requirement to return a different result based on upper or lower case.

Some libraries might do that, but others will not.

5. I should inquire as to whether you intend to use C or C++? What you have shown so far is C code.