Following is the code:
#include<stdio.h>
int main()
{
int alpha = 0, input;
while((input = getchar() != EOF))
{
if(isalpha(input))
alpha++;
}
printf("Num of alpha is %d", alpha);
return(0);
}
I'm getting error as
isalpha was not declared in this scope
when compiled on DevC++ compiler.
isalpha()is declared inctype.hIt might be good to know that even though the argument to
isalpha(and all theisxxxfamily functions) is anint, the behavior is undefined if the argument is negative. So if you're on a machine wherecharis signed as default, you might run into trouble unless you cast first. Like this:It can be a good habit to always cast for these functions. However, do NOT use casting as a goto for silencing warnings. It can easily hide errors. In most cases when a cast is needed, your code is wrong in some other way. Rant about casting
Another pitfall with these functions (and many other C functions that returns an
intas a Boolean) is that they are required to return zero on false, but are allowed to return any non-zero value on true. So a check like this is complete nonsense:Instead do any of these: